@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/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { JSONType } from './campaignConfiguration/types';
|
|
4
|
+
import { IExternalEventSourceConstructor } from './eventSource';
|
|
5
|
+
import { IExternalStorageConstructor } from './storage';
|
|
6
|
+
/**
|
|
7
|
+
* @param {number} updateInterval - update interval in _minutes_ for sdk configuration, minimum value is 1 minute
|
|
8
|
+
* @defaultvalue 60
|
|
9
|
+
*
|
|
10
|
+
* @param {Environment} environment - feature flag environment
|
|
11
|
+
* @defaultvalue Environment.Production
|
|
12
|
+
* */
|
|
13
|
+
export type SDKConfigurationType = {
|
|
14
|
+
updateInterval?: number;
|
|
15
|
+
environment?: Environment;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} siteCode - client's siteCode defined on Kameleoon platform
|
|
19
|
+
* @param {Partial<SDKConfigurationType>} configuration - client's configuration
|
|
20
|
+
* @param {InternalSDKConfigurationType} internalConfiguration - internal configuration for sdk core to be initialized with certain parameters to certain type of JavaScript SDK
|
|
21
|
+
* */
|
|
22
|
+
export type SDKCoreParameters = {
|
|
23
|
+
siteCode: string;
|
|
24
|
+
configuration?: Partial<SDKConfigurationType>;
|
|
25
|
+
internalConfiguration: InternalSDKConfigurationType;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @param {IExternalStorage | undefiend} externalStorage - external file system storage implemented outside client initialization
|
|
29
|
+
* @param {IExternalEventSourceConstructor | undefiend} externalEventSource - constructor for building external event source implementation
|
|
30
|
+
* */
|
|
31
|
+
export type InternalSDKConfigurationType = {
|
|
32
|
+
externalStorage: IExternalStorageConstructor;
|
|
33
|
+
externalEventSource: IExternalEventSourceConstructor;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* @readonly
|
|
37
|
+
* @enum {string} an Enum containing all possible variants of environment, passed as an argument to KameleoonClient `configuration`s `environment` field
|
|
38
|
+
* */
|
|
39
|
+
export declare enum Environment {
|
|
40
|
+
Production = "production",
|
|
41
|
+
Staging = "staging",
|
|
42
|
+
Development = "development"
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @readonly
|
|
46
|
+
* @enum {string} an Enum containing all possible variants of feature variable types
|
|
47
|
+
* */
|
|
48
|
+
export declare enum VariableType {
|
|
49
|
+
BOOLEAN = "BOOLEAN",
|
|
50
|
+
NUMBER = "NUMBER",
|
|
51
|
+
STRING = "STRING",
|
|
52
|
+
JSON = "JSON"
|
|
53
|
+
}
|
|
54
|
+
export type BooleanVariableType = {
|
|
55
|
+
type: VariableType.BOOLEAN;
|
|
56
|
+
value: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type NumberVariableType = {
|
|
59
|
+
type: VariableType.NUMBER;
|
|
60
|
+
value: number;
|
|
61
|
+
};
|
|
62
|
+
export type StringVariableType = {
|
|
63
|
+
type: VariableType.STRING;
|
|
64
|
+
value: string;
|
|
65
|
+
};
|
|
66
|
+
export type JSONVariableType = {
|
|
67
|
+
type: VariableType.JSON;
|
|
68
|
+
value: JSONType;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @type FeatureVariableResultType - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `FeatureVariableType` enum, if the `type` is `FeatureVariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
|
|
72
|
+
* */
|
|
73
|
+
export type FeatureVariableResultType = BooleanVariableType | NumberVariableType | StringVariableType | JSONVariableType;
|
|
74
|
+
export declare enum Milliseconds {
|
|
75
|
+
Second = 1000,
|
|
76
|
+
Minute = 60000,
|
|
77
|
+
Hour = 3600000
|
|
78
|
+
}
|
|
79
|
+
export type TrackConversionParamsType = {
|
|
80
|
+
visitorCode: string;
|
|
81
|
+
goalId: number;
|
|
82
|
+
revenue: number;
|
|
83
|
+
};
|
|
84
|
+
export type ExperimentType = {
|
|
85
|
+
id: number;
|
|
86
|
+
name: string;
|
|
87
|
+
};
|
|
88
|
+
export type FeatureFlagType = {
|
|
89
|
+
id: number;
|
|
90
|
+
key: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
|
|
94
|
+
* @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform
|
|
95
|
+
* @param {string} variableKey - key of the variable to be found for a feature flag with provided `featureKey`, can be found on Kameleoon Platform
|
|
96
|
+
* */
|
|
97
|
+
export type GetFeatureFlagVariableParamsType = {
|
|
98
|
+
visitorCode: string;
|
|
99
|
+
featureKey: string;
|
|
100
|
+
variableKey: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* @param {string} domain - domain which cookie belongs to
|
|
104
|
+
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
|
|
105
|
+
* */
|
|
106
|
+
export type GetResultCookieParametersType = {
|
|
107
|
+
domain: string;
|
|
108
|
+
visitorCode: string;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* @param {Request} request - request object to get the cookie from
|
|
112
|
+
* @param {Response} response - response object to write the updated cookie to
|
|
113
|
+
* @param {string} domain - domain which cookie belongs to
|
|
114
|
+
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
|
|
115
|
+
* */
|
|
116
|
+
export type ServerGetVisitorCodeParametersType = {
|
|
117
|
+
request: IncomingMessage;
|
|
118
|
+
response: ServerResponse;
|
|
119
|
+
domain: string;
|
|
120
|
+
defaultVisitorCode?: string;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} domain - domain which cookie belongs to
|
|
124
|
+
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
|
|
125
|
+
* */
|
|
126
|
+
export type ClientGetVisitorCodeParametersType = {
|
|
127
|
+
domain: string;
|
|
128
|
+
defaultVisitorCode?: string;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
|
|
132
|
+
* */
|
|
133
|
+
export type MobileGetVisitorCodeParametersType = {
|
|
134
|
+
defaultVisitorCode?: string;
|
|
135
|
+
};
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Milliseconds = exports.VariableType = exports.Environment = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @readonly
|
|
6
|
+
* @enum {string} an Enum containing all possible variants of environment, passed as an argument to KameleoonClient `configuration`s `environment` field
|
|
7
|
+
* */
|
|
8
|
+
var Environment;
|
|
9
|
+
(function (Environment) {
|
|
10
|
+
Environment["Production"] = "production";
|
|
11
|
+
Environment["Staging"] = "staging";
|
|
12
|
+
Environment["Development"] = "development";
|
|
13
|
+
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
14
|
+
/**
|
|
15
|
+
* @readonly
|
|
16
|
+
* @enum {string} an Enum containing all possible variants of feature variable types
|
|
17
|
+
* */
|
|
18
|
+
var VariableType;
|
|
19
|
+
(function (VariableType) {
|
|
20
|
+
VariableType["BOOLEAN"] = "BOOLEAN";
|
|
21
|
+
VariableType["NUMBER"] = "NUMBER";
|
|
22
|
+
VariableType["STRING"] = "STRING";
|
|
23
|
+
VariableType["JSON"] = "JSON";
|
|
24
|
+
})(VariableType = exports.VariableType || (exports.VariableType = {}));
|
|
25
|
+
var Milliseconds;
|
|
26
|
+
(function (Milliseconds) {
|
|
27
|
+
Milliseconds[Milliseconds["Second"] = 1000] = "Second";
|
|
28
|
+
Milliseconds[Milliseconds["Minute"] = 60000] = "Minute";
|
|
29
|
+
Milliseconds[Milliseconds["Hour"] = 3600000] = "Hour";
|
|
30
|
+
})(Milliseconds = exports.Milliseconds || (exports.Milliseconds = {}));
|
|
3
31
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAqCA;;;KAGK;AACL,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,kCAAmB,CAAA;IACnB,0CAA2B,CAAA;AAC7B,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAED;;;KAGK;AACL,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,iCAAiB,CAAA;IACjB,iCAAiB,CAAA;IACjB,6BAAa,CAAA;AACf,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB;AAmBD,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,sDAAa,CAAA;IACb,uDAAiC,CAAA;IACjC,qDAA+B,CAAA;AACjC,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VISITOR_CODE_MAX_LENGTH = 255;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utilities/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Utilities } from './utilities';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Utilities = void 0;
|
|
4
|
+
var utilities_1 = require("./utilities");
|
|
5
|
+
Object.defineProperty(exports, "Utilities", { enumerable: true, get: function () { return utilities_1.Utilities; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CampaignConfiguration } from '../campaignConfiguration';
|
|
2
|
+
import { Requester } from '../requester';
|
|
3
|
+
import { SegmentType, TargetingDataItemType } from '../targeting';
|
|
4
|
+
import { VariationConfiguration, FeatureFlagVariationType } from '../variationConfiguration';
|
|
5
|
+
export type CheckTargetingParamsType = {
|
|
6
|
+
segment: SegmentType | null;
|
|
7
|
+
experimentId: number | null;
|
|
8
|
+
visitorCode: string;
|
|
9
|
+
targetingData?: TargetingDataItemType[];
|
|
10
|
+
variationConfiguration?: VariationConfiguration;
|
|
11
|
+
};
|
|
12
|
+
export type TrackExperimentationRuleParamsType = {
|
|
13
|
+
featureFlagVariation: FeatureFlagVariationType;
|
|
14
|
+
campaignConfiguration: CampaignConfiguration;
|
|
15
|
+
visitorCode: string;
|
|
16
|
+
requester: Requester;
|
|
17
|
+
userAgent?: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utilities/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Result } from 'ts-res';
|
|
2
|
+
import { KameleoonError } from '../kameleoonError';
|
|
3
|
+
import { CheckTargetingParamsType, TrackExperimentationRuleParamsType } from './types';
|
|
4
|
+
import { FeatureVariableResultType } from '../types';
|
|
5
|
+
import { CampaignConfiguration, FeatureVariableType } from '../campaignConfiguration';
|
|
6
|
+
export declare class Utilities {
|
|
7
|
+
static checkTargeting({ segment, visitorCode, targetingData, experimentId, variationConfiguration, }: CheckTargetingParamsType): Result<boolean, KameleoonError>;
|
|
8
|
+
static validateVisitorCode(visitorCode: string): Result<void, KameleoonError>;
|
|
9
|
+
static getDataUrl(visitorCode: string, campaignConfiguration: CampaignConfiguration): string;
|
|
10
|
+
static trackExperimentationRule({ featureFlagVariation, campaignConfiguration, visitorCode, requester, userAgent, }: TrackExperimentationRuleParamsType): void;
|
|
11
|
+
static parseFeatureVariable(variable: FeatureVariableType): Result<FeatureVariableResultType, KameleoonError>;
|
|
12
|
+
static getUserAgent(visitorCode: string, campaignConfiguration: CampaignConfiguration): string | undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Utilities = void 0;
|
|
4
|
+
const ts_res_1 = require("ts-res");
|
|
5
|
+
const kameleoonError_1 = require("../kameleoonError");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const targeting_1 = require("../targeting");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const campaignConfiguration_1 = require("../campaignConfiguration");
|
|
10
|
+
const kameleoonData_1 = require("../kameleoonData");
|
|
11
|
+
class Utilities {
|
|
12
|
+
static checkTargeting({ segment, visitorCode, targetingData, experimentId, variationConfiguration, }) {
|
|
13
|
+
if (!segment || !segment.conditionsData.firstLevel.length) {
|
|
14
|
+
return (0, ts_res_1.Ok)(true);
|
|
15
|
+
}
|
|
16
|
+
if (!variationConfiguration) {
|
|
17
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization));
|
|
18
|
+
}
|
|
19
|
+
let variations = {};
|
|
20
|
+
const assignedVariationsResult = variationConfiguration.getAssignedVariations(visitorCode);
|
|
21
|
+
if (assignedVariationsResult.ok) {
|
|
22
|
+
variations = assignedVariationsResult.data;
|
|
23
|
+
}
|
|
24
|
+
const targetingTree = new targeting_1.TargetingTree(segment);
|
|
25
|
+
const result = targetingTree.evaluate({
|
|
26
|
+
targetingData: targetingData || [],
|
|
27
|
+
variationData: variations,
|
|
28
|
+
experimentId,
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
static validateVisitorCode(visitorCode) {
|
|
33
|
+
if (visitorCode.length > constants_1.VISITOR_CODE_MAX_LENGTH) {
|
|
34
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.VisitorCodeMaxLength));
|
|
35
|
+
}
|
|
36
|
+
return (0, ts_res_1.Ok)();
|
|
37
|
+
}
|
|
38
|
+
static getDataUrl(visitorCode, campaignConfiguration) {
|
|
39
|
+
const unsentData = campaignConfiguration.getUnsentData(visitorCode);
|
|
40
|
+
const concatenatedUrl = unsentData.reduce((previousItem, currentItem) => {
|
|
41
|
+
return previousItem + currentItem.url;
|
|
42
|
+
}, '');
|
|
43
|
+
return concatenatedUrl;
|
|
44
|
+
}
|
|
45
|
+
static trackExperimentationRule({ featureFlagVariation, campaignConfiguration, visitorCode, requester, userAgent, }) {
|
|
46
|
+
const { variationId, rule } = featureFlagVariation;
|
|
47
|
+
if (!rule || rule.type !== campaignConfiguration_1.RuleType.EXPERIMENTATION) {
|
|
48
|
+
throw new Error('Internal usage error, make sure to use `trackExperimentationRule` for existing rule with type `RuleType.EXPERIMENTATION`');
|
|
49
|
+
}
|
|
50
|
+
const dataUrl = this.getDataUrl(visitorCode, campaignConfiguration);
|
|
51
|
+
const resultVariationId = variationId || 0;
|
|
52
|
+
const isUnallocated = !variationId;
|
|
53
|
+
const callback = () => campaignConfiguration.clearUnsentData;
|
|
54
|
+
requester.trackExperiment({
|
|
55
|
+
visitorCode,
|
|
56
|
+
isUnallocated,
|
|
57
|
+
body: dataUrl,
|
|
58
|
+
callback,
|
|
59
|
+
// --- Note ---
|
|
60
|
+
// For `RuleType.EXPERIMENTATION` `experimentId` can not be null
|
|
61
|
+
experimentId: rule.experimentId,
|
|
62
|
+
variationId: resultVariationId,
|
|
63
|
+
userAgent,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static parseFeatureVariable(variable) {
|
|
67
|
+
const { type, value } = variable;
|
|
68
|
+
switch (type) {
|
|
69
|
+
case types_1.VariableType.BOOLEAN:
|
|
70
|
+
return (0, ts_res_1.Ok)({
|
|
71
|
+
type,
|
|
72
|
+
value: Boolean(value),
|
|
73
|
+
});
|
|
74
|
+
case types_1.VariableType.STRING:
|
|
75
|
+
return (0, ts_res_1.Ok)({
|
|
76
|
+
type,
|
|
77
|
+
value: String(value),
|
|
78
|
+
});
|
|
79
|
+
case types_1.VariableType.NUMBER:
|
|
80
|
+
const numberValue = Number(value);
|
|
81
|
+
if (Number.isNaN(numberValue)) {
|
|
82
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.NumberParse, String(value)));
|
|
83
|
+
}
|
|
84
|
+
return (0, ts_res_1.Ok)({
|
|
85
|
+
type,
|
|
86
|
+
value: numberValue,
|
|
87
|
+
});
|
|
88
|
+
case types_1.VariableType.JSON:
|
|
89
|
+
try {
|
|
90
|
+
const jsonValue = JSON.parse(String(variable.value));
|
|
91
|
+
return (0, ts_res_1.Ok)({
|
|
92
|
+
type,
|
|
93
|
+
value: jsonValue,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.JSONParse, err));
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
(0, kameleoonError_1.exhaustCheck)(type);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
static getUserAgent(visitorCode, campaignConfiguration) {
|
|
104
|
+
const isUserAgent = (data) => data.type === kameleoonData_1.KameleoonData.UserAgent;
|
|
105
|
+
const targetingData = campaignConfiguration.storedTargetingData[visitorCode];
|
|
106
|
+
if (targetingData) {
|
|
107
|
+
const filteredData = targetingData
|
|
108
|
+
.map((item) => item.data)
|
|
109
|
+
.filter(isUserAgent);
|
|
110
|
+
if (filteredData.length) {
|
|
111
|
+
const [userAgentData] = filteredData;
|
|
112
|
+
return userAgentData.value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Utilities = Utilities;
|
|
119
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../src/utilities/utilities.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AACzC,sDAI2B;AAM3B,oCAAmE;AACnE,4CAA6C;AAC7C,2CAAsD;AACtD,oEAKkC;AAClC,oDAI0B;AAE1B,MAAa,SAAS;IACpB,MAAM,CAAC,cAAc,CAAC,EACpB,OAAO,EACP,WAAW,EACX,aAAa,EACb,YAAY,EACZ,sBAAsB,GACG;QACzB,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE;YACzD,OAAO,IAAA,WAAE,EAAC,IAAI,CAAC,CAAC;SACjB;QAED,IAAI,CAAC,sBAAs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+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VariationConfiguration = void 0;
|
|
4
|
+
var variationConfiguration_1 = require("./variationConfiguration");
|
|
5
|
+
Object.defineProperty(exports, "VariationConfiguration", { enumerable: true, get: function () { return variationConfiguration_1.VariationConfiguration; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/variationConfiguration/index.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FeatureFlagType, RuleItemType } from '../campaignConfiguration';
|
|
2
|
+
import { TargetingDataItemType } from '../targeting';
|
|
3
|
+
export type VariationType = {
|
|
4
|
+
variationId: number;
|
|
5
|
+
assignmentDate: string;
|
|
6
|
+
};
|
|
7
|
+
export type UpdateStorageParamsType = {
|
|
8
|
+
visitorCode: string;
|
|
9
|
+
experimentId: string;
|
|
10
|
+
variationId: number;
|
|
11
|
+
};
|
|
12
|
+
export type FeatureFlagVariationType = {
|
|
13
|
+
variationKey: string;
|
|
14
|
+
variationId: number | null;
|
|
15
|
+
featureFlagId: number;
|
|
16
|
+
featureKey: string;
|
|
17
|
+
rule: RuleItemType | null;
|
|
18
|
+
};
|
|
19
|
+
export type GetFeatureFlagVariationParametersType = {
|
|
20
|
+
visitorCode: string;
|
|
21
|
+
featureFlag: FeatureFlagType;
|
|
22
|
+
targetingData?: TargetingDataItemType[];
|
|
23
|
+
withAssignment?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type GetAssignedRuleVariationResultType = Pick<FeatureFlagVariationType, 'variationId' | 'variationKey'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/variationConfiguration/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RespoolTimeType } from '../campaignConfiguration/types';
|
|
2
|
+
import { VariationType } from './types';
|
|
3
|
+
interface IVariation {
|
|
4
|
+
readonly id: number;
|
|
5
|
+
isValid: (respoolTime?: RespoolTimeType[]) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class Variation implements IVariation {
|
|
8
|
+
variationData?: VariationType;
|
|
9
|
+
constructor(variationData?: VariationType);
|
|
10
|
+
get id(): number;
|
|
11
|
+
isValid(respoolTime?: RespoolTimeType[]): boolean;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Variation = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class Variation {
|
|
6
|
+
constructor(variationData) {
|
|
7
|
+
this.variationData = variationData;
|
|
8
|
+
}
|
|
9
|
+
get id() {
|
|
10
|
+
if (!this.variationData) {
|
|
11
|
+
throw new Error("Internal usage error: Check if the variation `isValid`, before getting it's `id`");
|
|
12
|
+
}
|
|
13
|
+
return this.variationData.variationId;
|
|
14
|
+
}
|
|
15
|
+
isValid(respoolTime) {
|
|
16
|
+
const variation = this.variationData;
|
|
17
|
+
if (!variation) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// --- Note ---
|
|
21
|
+
// - Respool is a kind of shuffle parameter
|
|
22
|
+
// it's presence indicates that variations assigned to
|
|
23
|
+
// user has changed at certain time (time is the value of `respoolTime` in seconds)
|
|
24
|
+
// - So the variation is valid unless it has been shuffled after it's assignment
|
|
25
|
+
if (respoolTime === null || respoolTime === void 0 ? void 0 : respoolTime.length) {
|
|
26
|
+
const assignmentTime = new Date(Date.parse(variation.assignmentDate)).getTime() /
|
|
27
|
+
types_1.Milliseconds.Second;
|
|
28
|
+
const variationRespoolTime = respoolTime.find((respool) => respool.variationId === String(variation.variationId));
|
|
29
|
+
if (!variationRespoolTime) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return assignmentTime > variationRespoolTime.value;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Variation = Variation;
|
|
38
|
+
//# sourceMappingURL=variation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variation.js","sourceRoot":"","sources":["../../src/variationConfiguration/variation.ts"],"names":[],"mappings":";;;AACA,oCAAwC;AAQxC,MAAa,SAAS;IAGpB,YAAY,aAA6B;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,IAAI,EAAE;QACJ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;SACH;QAED,OAAO,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC;IACxC,CAAC;IAEM,OAAO,CAAC,WAA+B;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;QAErC,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,KAAK,CAAC;SACd;QAED,eAAe;QACf,2CAA2C;QAC3C,sDAAsD;QACtD,mFAAmF;QACnF,gFAAgF;QAChF,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE;YACvB,MAAM,cAAc,GAClB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,EAAE;gBACxD,oBAAY,CAAC,MAAM,CAAC;YACtB,MAAM,oBAAoB,GAAG,WAAW,CAAC,IAAI,CAC3C,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,KAAK,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CACnE,CAAC;YAEF,IAAI,CAAC,oBAAoB,EAAE;gBACzB,OAAO,IAAI,CAAC;aACb;YAED,OAAO,cAAc,GAAG,oBAAoB,CAAC,KAAK,CAAC;SACpD;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9CD,8BA8CC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Result } from 'ts-res';
|
|
2
|
+
import { ExperimentItemType } from '../campaignConfiguration';
|
|
3
|
+
import { KameleoonError } from '../kameleoonError';
|
|
4
|
+
import { IStorage, VariationDataType, ExperimentVariationsType } from '../storage';
|
|
5
|
+
import { FeatureFlagVariationType, GetFeatureFlagVariationParametersType } from './types';
|
|
6
|
+
interface IVariationConfiguration {
|
|
7
|
+
/**
|
|
8
|
+
* @method getAssociatedVariationId - gets the id of a variation assigned to a visitor with `visitorCode` from the storage. If the visitor doesn't have associated variation yet, assigns a new one, stores it and returns it's id.
|
|
9
|
+
* */
|
|
10
|
+
getAssociatedVariationId: (visitorCode: string, experimentId: number) => Result<number, KameleoonError>;
|
|
11
|
+
/**
|
|
12
|
+
* @method getAssignedVariations - obtains experiments with according variations that are *already assigned* and *stored* in the `variationStorage`. If `getAssociatedVariationId` hadn't been called before, there will be no variations to get.
|
|
13
|
+
* */
|
|
14
|
+
getAssignedVariations(visitorCode: string): Result<ExperimentVariationsType, KameleoonError>;
|
|
15
|
+
/**
|
|
16
|
+
* @method getFeatureFlagVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage
|
|
17
|
+
* */
|
|
18
|
+
getFeatureFlagVariation: (params: GetFeatureFlagVariationParametersType) => Result<FeatureFlagVariationType, KameleoonError>;
|
|
19
|
+
/**
|
|
20
|
+
* @method getExperimentVariation - obtains variation for the experiment by calculating the variation for the visitor *without assigning* it to a visitor
|
|
21
|
+
* */
|
|
22
|
+
getExperimentVariation: (visitorCode: string, experiment: ExperimentItemType) => Result<number, KameleoonError>;
|
|
23
|
+
}
|
|
24
|
+
export declare class VariationConfiguration implements IVariationConfiguration {
|
|
25
|
+
private experiments;
|
|
26
|
+
private storage;
|
|
27
|
+
constructor(experiments: ExperimentItemType[], externalStorage: IStorage<VariationDataType>);
|
|
28
|
+
getAssociatedVariationId: (visitorCode: string, experimentId: number) => Result<number, KameleoonError>;
|
|
29
|
+
getAssignedVariations(visitorCode: string): Result<ExperimentVariationsType, KameleoonError>;
|
|
30
|
+
getFeatureFlagVariation({ visitorCode, featureFlag, targetingData, withAssignment, }: GetFeatureFlagVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>;
|
|
31
|
+
getExperimentVariation(visitorCode: string, experiment: ExperimentItemType): Result<number, KameleoonError>;
|
|
32
|
+
private assignVariation;
|
|
33
|
+
private updateStorageData;
|
|
34
|
+
private getAssignedRuleVariation;
|
|
35
|
+
}
|
|
36
|
+
export {};
|