@kameleoon/javascript-sdk-core 1.1.0 → 2.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/dist/campaignConfiguration/campaignConfiguration.d.ts +2 -1
- package/dist/campaignConfiguration/campaignConfiguration.js +239 -197
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
- package/dist/campaignConfiguration/constants.js +20 -14
- package/dist/campaignConfiguration/constants.js.map +1 -1
- package/dist/campaignConfiguration/index.js +78 -6
- package/dist/campaignConfiguration/index.js.map +1 -1
- package/dist/campaignConfiguration/types.d.ts +3 -2
- package/dist/campaignConfiguration/types.js +53 -45
- package/dist/campaignConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +1 -1
- package/dist/clientSettings/clientSettings.js +28 -21
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/index.js +18 -4
- package/dist/clientSettings/index.js.map +1 -1
- package/dist/clientSettings/types.d.ts +1 -1
- package/dist/clientSettings/types.js +4 -1
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/constants.js +22 -14
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/constants.js +6 -2
- package/dist/eventSource/constants.js.map +1 -1
- package/dist/eventSource/externalEventSource.js +28 -20
- package/dist/eventSource/externalEventSource.js.map +1 -1
- package/dist/eventSource/index.js +49 -6
- package/dist/eventSource/index.js.map +1 -1
- package/dist/eventSource/types.d.ts +1 -1
- package/dist/eventSource/types.js +4 -1
- package/dist/eventSource/types.js.map +1 -1
- package/dist/hasher/constants.js +6 -2
- package/dist/hasher/constants.js.map +1 -1
- package/dist/hasher/hasher.js +35 -24
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/index.js +11 -4
- package/dist/hasher/index.js.map +1 -1
- package/dist/hasher/types.js +4 -1
- package/dist/hasher/types.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +297 -27
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +16 -16
- package/dist/kameleoonClient.js +307 -236
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonData/browser.js +37 -32
- package/dist/kameleoonData/browser.js.map +1 -1
- package/dist/kameleoonData/constants.js +6 -2
- package/dist/kameleoonData/constants.js.map +1 -1
- package/dist/kameleoonData/conversion.js +47 -40
- package/dist/kameleoonData/conversion.js.map +1 -1
- package/dist/kameleoonData/customData.js +62 -58
- package/dist/kameleoonData/customData.js.map +1 -1
- package/dist/kameleoonData/device.js +37 -32
- package/dist/kameleoonData/device.js.map +1 -1
- package/dist/kameleoonData/index.js +101 -18
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/nonce.js +25 -13
- package/dist/kameleoonData/nonce.js.map +1 -1
- package/dist/kameleoonData/pageView.js +52 -44
- package/dist/kameleoonData/pageView.js.map +1 -1
- package/dist/kameleoonData/types.js +41 -26
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonData/userAgent.js +33 -24
- package/dist/kameleoonData/userAgent.js.map +1 -1
- package/dist/kameleoonError/constants.js +25 -21
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/helpers.js +6 -4
- package/dist/kameleoonError/helpers.js.map +1 -1
- package/dist/kameleoonError/index.js +25 -8
- package/dist/kameleoonError/index.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.js +64 -53
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.js +26 -22
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/kameleoonUtils.js +34 -33
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +6 -7
- package/dist/requester/constants.js +58 -45
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.d.ts +2 -2
- package/dist/requester/index.js +67 -8
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +7 -7
- package/dist/requester/requester.js +100 -113
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +38 -10
- package/dist/requester/types.js +14 -36
- package/dist/requester/types.js.map +1 -1
- package/dist/storage/constants.js +11 -7
- package/dist/storage/constants.js.map +1 -1
- package/dist/storage/externalStorage.js +33 -26
- package/dist/storage/externalStorage.js.map +1 -1
- package/dist/storage/index.js +55 -6
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/types.js +4 -1
- package/dist/storage/types.js.map +1 -1
- package/dist/targeting/conditions/conditionFactory.js +24 -19
- package/dist/targeting/conditions/conditionFactory.js.map +1 -1
- package/dist/targeting/conditions/customDataCondition.js +99 -88
- package/dist/targeting/conditions/customDataCondition.js.map +1 -1
- package/dist/targeting/conditions/exclusiveExperimentCondition.js +27 -15
- package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/index.js +45 -10
- package/dist/targeting/conditions/index.js.map +1 -1
- package/dist/targeting/conditions/targetExperimentCondition.js +54 -32
- package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/types.js +4 -1
- package/dist/targeting/conditions/types.js.map +1 -1
- package/dist/targeting/index.js +79 -13
- package/dist/targeting/index.js.map +1 -1
- package/dist/targeting/targetingNode.js +41 -33
- package/dist/targeting/targetingNode.js.map +1 -1
- package/dist/targeting/targetingTree.js +125 -104
- package/dist/targeting/targetingTree.js.map +1 -1
- package/dist/targeting/types.js +99 -91
- package/dist/targeting/types.js.map +1 -1
- package/dist/types.d.ts +17 -2
- package/dist/types.js +50 -21
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.js +6 -2
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/index.js +11 -4
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/types.d.ts +1 -1
- package/dist/utilities/types.js +4 -1
- package/dist/utilities/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +2 -2
- package/dist/utilities/utilities.js +117 -105
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/variationConfiguration/index.js +24 -4
- package/dist/variationConfiguration/index.js.map +1 -1
- package/dist/variationConfiguration/types.js +4 -1
- package/dist/variationConfiguration/types.js.map +1 -1
- package/dist/variationConfiguration/variation.js +35 -28
- package/dist/variationConfiguration/variation.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.d.ts +5 -5
- package/dist/variationConfiguration/variationConfiguration.js +270 -228
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/package.json +7 -5
package/dist/storage/index.js
CHANGED
|
@@ -1,8 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ClientDataType", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _types.ClientDataType;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ExperimentVariationsType", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _types.ExperimentVariationsType;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ExternalStorage", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _externalStorage.ExternalStorage;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "IExternalStorage", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _types.IExternalStorage;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "IExternalStorageConstructor", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _types.IExternalStorageConstructor;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "IStorage", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _types.IStorage;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "KameleoonStorageKey", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _constants.KameleoonStorageKey;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "VariationDataType", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _types.VariationDataType;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
var _constants = require("./constants");
|
|
55
|
+
var _externalStorage = require("./externalStorage");
|
|
56
|
+
var _types = require("./types");
|
|
8
57
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_constants","require","_externalStorage","_types"],"sources":["../../src/storage/index.ts"],"sourcesContent":["export { KameleoonStorageKey } from './constants';\nexport { ExternalStorage } from './externalStorage';\nexport {\n IStorage,\n ClientDataType,\n IExternalStorage,\n VariationDataType,\n ExperimentVariationsType,\n IExternalStorageConstructor,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA"}
|
package/dist/storage/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/storage/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { ConfigurationDataType } from '../campaignConfiguration';\nimport { KameleoonError } from '../kameleoonError';\nimport { TargetingDataType } from '../targeting';\nimport { VariationType } from '../variationConfiguration';\nimport { KameleoonStorageKey } from './constants';\n\nexport type ClientDataType = {\n kameleoonTargetingData: TargetingDataType;\n kameleoonConfiguration: ConfigurationDataType;\n lastUpdate: string;\n};\n\nexport type ExperimentVariationsType = {\n [experimentId: string]: VariationType;\n};\n\nexport type VariationDataType = {\n [visitorCode: string]: ExperimentVariationsType;\n};\n\nexport type StorageDataType = ClientDataType | VariationDataType;\n\nexport interface IStorage<T> {\n read: () => Result<T, KameleoonError>;\n write: (data: T) => Result<void, KameleoonError>;\n}\n\n/**\n * @interface an interface of External Constructor for Storage which must be implemented by the wrapper constructor to initialize new `IExternalStorage` in order to be able to pass necessary initialization parameters\n * */\nexport interface IExternalStorageConstructor {\n /**\n * @method initialize - creates and instance of `IExternalStorage` and returns it\n * @param {KameleoonStorageKey} key - an enum variant containing keys for Kameleoon SDK related data stored on storage\n * @returns {IExternalEventSource} an initialized instance of `IExternalEventSource`\n * */\n initialize: (key: KameleoonStorageKey) => IExternalStorage;\n}\n\n/**\n * @interface an interface of External Storage which must be implemented to be used as external storage for initialized JS SDK Core.\n * Note: Only React Native SDK supports external storage for the moment\n * */\nexport interface IExternalStorage {\n /**\n * @property key - an Enum `KameleoonStorageKey` variant containing a key for Kameleoon SDK related data stored on storage\n * */\n readonly key: KameleoonStorageKey;\n /**\n * @method read - reads data from the storage\n * @returns {Result<string, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains `data` field with a type `string`, if not contains `error` field with a type of `KameleoonError`\n * */\n read: () => Result<string, KameleoonError>;\n /**\n * @method write - writes data to storage\n * @param {string} data - string representation of data\n * @returns {Result<void, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains an empty `data`, if not contains `error` field with a type of `KameleoonError`\n * */\n write: (data: string) => Result<void, KameleoonError>;\n}\n"],"mappings":""}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.ConditionFactory = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var _tsRes = require("ts-res");
|
|
8
|
+
var _kameleoonError = require("../../kameleoonError");
|
|
9
|
+
var _types = require("../types");
|
|
10
|
+
var _customDataCondition = require("./customDataCondition");
|
|
11
|
+
var _exclusiveExperimentCondition = require("./exclusiveExperimentCondition");
|
|
12
|
+
var _targetExperimentCondition = require("./targetExperimentCondition");
|
|
10
13
|
class ConditionFactory {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
static createCondition(data) {
|
|
15
|
+
const {
|
|
16
|
+
targetingType
|
|
17
|
+
} = data;
|
|
18
|
+
switch (targetingType) {
|
|
19
|
+
case _types.TargetingType.CUSTOM_DATUM:
|
|
20
|
+
return (0, _tsRes.Ok)(new _customDataCondition.CustomDataCondition(data));
|
|
21
|
+
case _types.TargetingType.EXCLUSIVE_EXPERIMENT:
|
|
22
|
+
return (0, _tsRes.Ok)(new _exclusiveExperimentCondition.ExclusiveExperimentCondition(data));
|
|
23
|
+
case _types.TargetingType.TARGET_EXPERIMENT:
|
|
24
|
+
return (0, _tsRes.Ok)(new _targetExperimentCondition.TargetExperimentCondition(data));
|
|
25
|
+
default:
|
|
26
|
+
return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.TargetingCondition, targetingType));
|
|
23
27
|
}
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
exports.ConditionFactory = ConditionFactory;
|
|
26
31
|
//# sourceMappingURL=conditionFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionFactory.js","
|
|
1
|
+
{"version":3,"file":"conditionFactory.js","names":["_tsRes","require","_kameleoonError","_types","_customDataCondition","_exclusiveExperimentCondition","_targetExperimentCondition","ConditionFactory","createCondition","data","targetingType","TargetingType","CUSTOM_DATUM","Ok","CustomDataCondition","EXCLUSIVE_EXPERIMENT","ExclusiveExperimentCondition","TARGET_EXPERIMENT","TargetExperimentCondition","Err","KameleoonError","KameleoonException","TargetingCondition","exports"],"sources":["../../../src/targeting/conditions/conditionFactory.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonError, KameleoonException } from '../../kameleoonError';\nimport { TargetingType } from '../types';\nimport { CustomDataCondition } from './customDataCondition';\nimport { ExclusiveExperimentCondition } from './exclusiveExperimentCondition';\nimport { TargetExperimentCondition } from './targetExperimentCondition';\nimport { ConditionDataType, ConditionType } from './types';\n\nexport class ConditionFactory {\n static createCondition(\n data: ConditionDataType,\n ): Result<ConditionType, KameleoonError> {\n const { targetingType } = data;\n\n switch (targetingType) {\n case TargetingType.CUSTOM_DATUM:\n return Ok(new CustomDataCondition(data));\n case TargetingType.EXCLUSIVE_EXPERIMENT:\n return Ok(new ExclusiveExperimentCondition(data));\n case TargetingType.TARGET_EXPERIMENT:\n return Ok(new TargetExperimentCondition(data));\n default:\n return Err(\n new KameleoonError(\n KameleoonException.TargetingCondition,\n targetingType,\n ),\n );\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA;AACA,IAAAK,0BAAA,GAAAL,OAAA;AAGO,MAAMM,gBAAgB,CAAC;EAC5B,OAAOC,eAAeA,CACpBC,IAAuB,EACgB;IACvC,MAAM;MAAEC;IAAc,CAAC,GAAGD,IAAI;IAE9B,QAAQC,aAAa;MACnB,KAAKC,oBAAa,CAACC,YAAY;QAC7B,OAAO,IAAAC,SAAE,EAAC,IAAIC,wCAAmB,CAACL,IAAI,CAAC,CAAC;MAC1C,KAAKE,oBAAa,CAACI,oBAAoB;QACrC,OAAO,IAAAF,SAAE,EAAC,IAAIG,0DAA4B,CAACP,IAAI,CAAC,CAAC;MACnD,KAAKE,oBAAa,CAACM,iBAAiB;QAClC,OAAO,IAAAJ,SAAE,EAAC,IAAIK,oDAAyB,CAACT,IAAI,CAAC,CAAC;MAChD;QACE,OAAO,IAAAU,UAAG,EACR,IAAIC,8BAAc,CAChBC,kCAAkB,CAACC,kBAAkB,EACrCZ,aAAa,CACd,CACF;IAAC;EAER;AACF;AAACa,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
|
|
@@ -1,99 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.CustomDataCondition = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
var _tsRes = require("ts-res");
|
|
8
|
+
var _kameleoonData = require("../../kameleoonData");
|
|
9
|
+
var _kameleoonError = require("../../kameleoonError");
|
|
10
|
+
var _types = require("../types");
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
14
|
class CustomDataCondition {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
constructor({
|
|
16
|
+
customDataIndex,
|
|
17
|
+
valueMatchType,
|
|
18
|
+
isInclude,
|
|
19
|
+
value
|
|
20
|
+
}) {
|
|
21
|
+
_defineProperty(this, "customDataIndex", void 0);
|
|
22
|
+
_defineProperty(this, "matchType", void 0);
|
|
23
|
+
_defineProperty(this, "inverseResult", void 0);
|
|
24
|
+
_defineProperty(this, "conditionValue", void 0);
|
|
25
|
+
_defineProperty(this, "error", void 0);
|
|
26
|
+
this.customDataIndex = Number(customDataIndex);
|
|
27
|
+
this.inverseResult = !(isInclude ?? true);
|
|
28
|
+
this.matchType = valueMatchType;
|
|
29
|
+
this.conditionValue = value;
|
|
30
|
+
}
|
|
31
|
+
evaluate({
|
|
32
|
+
targetingData
|
|
33
|
+
}) {
|
|
34
|
+
const isCustomData = data => data.type === _kameleoonData.KameleoonData.CustomData;
|
|
35
|
+
const filteredData = targetingData.map(item => item.data).filter(isCustomData).filter(item => item.index === this.customDataIndex);
|
|
36
|
+
if (filteredData.length) {
|
|
37
|
+
const lastDataItem = filteredData[filteredData.length - 1];
|
|
38
|
+
const {
|
|
39
|
+
value: customDataValue
|
|
40
|
+
} = lastDataItem;
|
|
41
|
+
const result = this.inverseResult ? !this.checkCondition(customDataValue) : this.checkCondition(customDataValue);
|
|
42
|
+
if (this.error) {
|
|
43
|
+
return (0, _tsRes.Err)(this.error);
|
|
44
|
+
}
|
|
45
|
+
return (0, _tsRes.Ok)(result);
|
|
14
46
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.filter((item) => item.index === this.customDataIndex);
|
|
21
|
-
if (filteredData.length) {
|
|
22
|
-
const lastDataItem = filteredData[filteredData.length - 1];
|
|
23
|
-
const { value: customDataValue } = lastDataItem;
|
|
24
|
-
const result = this.inverseResult
|
|
25
|
-
? !this.checkCondition(customDataValue)
|
|
26
|
-
: this.checkCondition(customDataValue);
|
|
27
|
-
if (this.error) {
|
|
28
|
-
return (0, ts_res_1.Err)(this.error);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return (0, ts_res_1.Ok)(result);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return (0, ts_res_1.Ok)(this.matchType === types_1.MatchTypeCustomData.UNDEFINED);
|
|
47
|
+
return (0, _tsRes.Ok)(this.matchType === _types.MatchTypeCustomData.UNDEFINED);
|
|
48
|
+
}
|
|
49
|
+
checkCondition(customDataValue) {
|
|
50
|
+
if (this.conditionValue === null) {
|
|
51
|
+
return false;
|
|
35
52
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
const resultData = new Set(result.data);
|
|
50
|
-
return Array.isArray(customDataValue)
|
|
51
|
-
? customDataValue.some((value) => resultData.has(value))
|
|
52
|
-
: result.data.includes(customDataValue);
|
|
53
|
-
}
|
|
54
|
-
if (Array.isArray(customDataValue)) {
|
|
55
|
-
return customDataValue.some((value) => this.checkCondition(value));
|
|
56
|
-
}
|
|
57
|
-
switch (this.matchType) {
|
|
58
|
-
case types_1.MatchTypeCustomData.CONTAINS:
|
|
59
|
-
return customDataValue.includes(this.conditionValue);
|
|
60
|
-
case types_1.MatchTypeCustomData.EXACT:
|
|
61
|
-
return customDataValue === this.conditionValue;
|
|
62
|
-
case types_1.MatchTypeCustomData.REGULAR_EXPRESSION:
|
|
63
|
-
return this.parseRegExp(this.conditionValue).test(customDataValue);
|
|
64
|
-
case types_1.MatchTypeCustomData.LOWER:
|
|
65
|
-
return Number(customDataValue) < Number(this.conditionValue);
|
|
66
|
-
case types_1.MatchTypeCustomData.EQUAL:
|
|
67
|
-
return Number(customDataValue) === Number(this.conditionValue);
|
|
68
|
-
case types_1.MatchTypeCustomData.GREATER:
|
|
69
|
-
return Number(customDataValue) > Number(this.conditionValue);
|
|
70
|
-
case types_1.MatchTypeCustomData.TRUE:
|
|
71
|
-
return customDataValue.toLowerCase() === 'true';
|
|
72
|
-
case types_1.MatchTypeCustomData.FALSE:
|
|
73
|
-
return customDataValue.toLowerCase() === 'false';
|
|
74
|
-
default:
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
53
|
+
|
|
54
|
+
// --- Note ---
|
|
55
|
+
// `AMONG_VALUES` is checked separately to avoid recursion overhead
|
|
56
|
+
// for `JSON.parse` inside `this.parseArray`
|
|
57
|
+
if (this.matchType === _types.MatchTypeCustomData.AMONG_VALUES) {
|
|
58
|
+
const result = this.parseArray(this.conditionValue);
|
|
59
|
+
if (!result.ok) {
|
|
60
|
+
this.error = result.error;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const resultData = new Set(result.data);
|
|
64
|
+
return Array.isArray(customDataValue) ? customDataValue.some(value => resultData.has(value)) : result.data.includes(customDataValue);
|
|
77
65
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const [_, expression, flags] = value.split('/');
|
|
81
|
-
return new RegExp(expression, flags);
|
|
82
|
-
}
|
|
83
|
-
return new RegExp(value);
|
|
66
|
+
if (Array.isArray(customDataValue)) {
|
|
67
|
+
return customDataValue.some(value => this.checkCondition(value));
|
|
84
68
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return (
|
|
69
|
+
switch (this.matchType) {
|
|
70
|
+
case _types.MatchTypeCustomData.CONTAINS:
|
|
71
|
+
return customDataValue.includes(this.conditionValue);
|
|
72
|
+
case _types.MatchTypeCustomData.EXACT:
|
|
73
|
+
return customDataValue === this.conditionValue;
|
|
74
|
+
case _types.MatchTypeCustomData.REGULAR_EXPRESSION:
|
|
75
|
+
return this.parseRegExp(this.conditionValue).test(customDataValue);
|
|
76
|
+
case _types.MatchTypeCustomData.LOWER:
|
|
77
|
+
return Number(customDataValue) < Number(this.conditionValue);
|
|
78
|
+
case _types.MatchTypeCustomData.EQUAL:
|
|
79
|
+
return Number(customDataValue) === Number(this.conditionValue);
|
|
80
|
+
case _types.MatchTypeCustomData.GREATER:
|
|
81
|
+
return Number(customDataValue) > Number(this.conditionValue);
|
|
82
|
+
case _types.MatchTypeCustomData.TRUE:
|
|
83
|
+
return customDataValue.toLowerCase() === 'true';
|
|
84
|
+
case _types.MatchTypeCustomData.FALSE:
|
|
85
|
+
return customDataValue.toLowerCase() === 'false';
|
|
86
|
+
default:
|
|
87
|
+
return false;
|
|
96
88
|
}
|
|
89
|
+
}
|
|
90
|
+
parseRegExp(value) {
|
|
91
|
+
if (value[0] === '/') {
|
|
92
|
+
const [_, expression, flags] = value.split('/');
|
|
93
|
+
return new RegExp(expression, flags);
|
|
94
|
+
}
|
|
95
|
+
return new RegExp(value);
|
|
96
|
+
}
|
|
97
|
+
parseArray(value) {
|
|
98
|
+
try {
|
|
99
|
+
const result = JSON.parse(value);
|
|
100
|
+
if (Array.isArray(result)) {
|
|
101
|
+
return (0, _tsRes.Ok)(result);
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck, err, value));
|
|
105
|
+
}
|
|
106
|
+
return (0, _tsRes.Ok)([]);
|
|
107
|
+
}
|
|
97
108
|
}
|
|
98
109
|
exports.CustomDataCondition = CustomDataCondition;
|
|
99
110
|
//# sourceMappingURL=customDataCondition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customDataCondition.js","
|
|
1
|
+
{"version":3,"file":"customDataCondition.js","names":["_tsRes","require","_kameleoonData","_kameleoonError","_types","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","CustomDataCondition","constructor","customDataIndex","valueMatchType","isInclude","inverseResult","matchType","conditionValue","evaluate","targetingData","isCustomData","data","type","KameleoonData","CustomData","filteredData","map","item","filter","index","length","lastDataItem","customDataValue","result","checkCondition","error","Err","Ok","MatchTypeCustomData","UNDEFINED","AMONG_VALUES","parseArray","ok","resultData","Set","Array","isArray","some","has","includes","CONTAINS","EXACT","REGULAR_EXPRESSION","parseRegExp","test","LOWER","EQUAL","GREATER","TRUE","toLowerCase","FALSE","_","expression","flags","split","RegExp","JSON","parse","err","KameleoonError","KameleoonException","AmongValuesCheck","exports"],"sources":["../../../src/targeting/conditions/customDataCondition.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport {\n KameleoonData,\n CustomDataType,\n KameleoonDataItemType,\n} from '../../kameleoonData';\nimport { KameleoonError, KameleoonException } from '../../kameleoonError';\nimport { EvaluationDataType, MatchTypeCustomData } from '../types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class CustomDataCondition implements ICondition {\n private customDataIndex: number;\n private matchType: MatchTypeCustomData | null;\n private inverseResult: boolean;\n private conditionValue: string | null;\n private error?: KameleoonError;\n\n constructor({\n customDataIndex,\n valueMatchType,\n isInclude,\n value,\n }: ConditionDataType) {\n this.customDataIndex = Number(customDataIndex);\n this.inverseResult = !(isInclude ?? true);\n this.matchType = valueMatchType;\n this.conditionValue = value;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const isCustomData = (\n data: KameleoonDataItemType,\n ): data is CustomDataType => data.type === KameleoonData.CustomData;\n\n const filteredData = targetingData\n .map((item) => item.data)\n .filter(isCustomData)\n .filter((item) => item.index === this.customDataIndex);\n\n if (filteredData.length) {\n const lastDataItem = filteredData[filteredData.length - 1];\n const { value: customDataValue } = lastDataItem;\n const result = this.inverseResult\n ? !this.checkCondition(customDataValue)\n : this.checkCondition(customDataValue);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n return Ok(this.matchType === MatchTypeCustomData.UNDEFINED);\n }\n\n private checkCondition(customDataValue: CustomDataType['value']): boolean {\n if (this.conditionValue === null) {\n return false;\n }\n\n // --- Note ---\n // `AMONG_VALUES` is checked separately to avoid recursion overhead\n // for `JSON.parse` inside `this.parseArray`\n if (this.matchType === MatchTypeCustomData.AMONG_VALUES) {\n const result = this.parseArray(this.conditionValue);\n\n if (!result.ok) {\n this.error = result.error;\n\n return false;\n }\n\n const resultData = new Set(result.data);\n\n return Array.isArray(customDataValue)\n ? customDataValue.some((value) => resultData.has(value))\n : result.data.includes(customDataValue);\n }\n\n if (Array.isArray(customDataValue)) {\n return customDataValue.some((value) => this.checkCondition(value));\n }\n\n switch (this.matchType) {\n case MatchTypeCustomData.CONTAINS:\n return customDataValue.includes(this.conditionValue);\n case MatchTypeCustomData.EXACT:\n return customDataValue === this.conditionValue;\n case MatchTypeCustomData.REGULAR_EXPRESSION:\n return this.parseRegExp(this.conditionValue).test(customDataValue);\n case MatchTypeCustomData.LOWER:\n return Number(customDataValue) < Number(this.conditionValue);\n case MatchTypeCustomData.EQUAL:\n return Number(customDataValue) === Number(this.conditionValue);\n case MatchTypeCustomData.GREATER:\n return Number(customDataValue) > Number(this.conditionValue);\n case MatchTypeCustomData.TRUE:\n return customDataValue.toLowerCase() === 'true';\n case MatchTypeCustomData.FALSE:\n return customDataValue.toLowerCase() === 'false';\n default:\n return false;\n }\n }\n\n private parseRegExp(value: string): RegExp {\n if (value[0] === '/') {\n const [_, expression, flags] = value.split('/');\n\n return new RegExp(expression, flags);\n }\n\n return new RegExp(value);\n }\n\n private parseArray(value: string): Result<string[], KameleoonError> {\n try {\n const result = JSON.parse(value);\n\n if (Array.isArray(result)) {\n return Ok(result);\n }\n } catch (err) {\n return Err(\n new KameleoonError(KameleoonException.AmongValuesCheck, err, value),\n );\n }\n\n return Ok([]);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAKA,IAAAE,eAAA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AAKrB,0BAAmB,CAACsB,KAAK;QAC5B,OAAO5B,eAAe,CAAC2B,WAAW,EAAE,KAAK,OAAO;MAClD;QACE,OAAO,KAAK;IAAC;EAEnB;EAEQN,WAAWA,CAAC/D,KAAa,EAAU;IACzC,IAAIA,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;MACpB,MAAM,CAACuE,CAAC,EAAEC,UAAU,EAAEC,KAAK,CAAC,GAAGzE,KAAK,CAAC0E,KAAK,CAAC,GAAG,CAAC;MAE/C,OAAO,IAAIC,MAAM,CAACH,UAAU,EAAEC,KAAK,CAAC;IACtC;IAEA,OAAO,IAAIE,MAAM,CAAC3E,KAAK,CAAC;EAC1B;EAEQmD,UAAUA,CAACnD,KAAa,EAAoC;IAClE,IAAI;MACF,MAAM2C,MAAM,GAAGiC,IAAI,CAACC,KAAK,CAAC7E,KAAK,CAAC;MAEhC,IAAIuD,KAAK,CAACC,OAAO,CAACb,MAAM,CAAC,EAAE;QACzB,OAAO,IAAAI,SAAE,EAACJ,MAAM,CAAC;MACnB;IACF,CAAC,CAAC,OAAOmC,GAAG,EAAE;MACZ,OAAO,IAAAhC,UAAG,EACR,IAAIiC,8BAAc,CAACC,kCAAkB,CAACC,gBAAgB,EAAEH,GAAG,EAAE9E,KAAK,CAAC,CACpE;IACH;IAEA,OAAO,IAAA+C,SAAE,EAAC,EAAE,CAAC;EACf;AACF;AAACmC,OAAA,CAAA9D,mBAAA,GAAAA,mBAAA"}
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.ExclusiveExperimentCondition = void 0;
|
|
4
|
-
|
|
7
|
+
var _tsRes = require("ts-res");
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
11
|
class ExclusiveExperimentCondition {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
constructor({
|
|
13
|
+
isInclude
|
|
14
|
+
}) {
|
|
15
|
+
_defineProperty(this, "inverseResult", void 0);
|
|
16
|
+
this.inverseResult = !(isInclude ?? true);
|
|
17
|
+
}
|
|
18
|
+
evaluate({
|
|
19
|
+
experimentId,
|
|
20
|
+
variationData
|
|
21
|
+
}) {
|
|
22
|
+
const keys = Object.keys(variationData);
|
|
23
|
+
const isEmpty = !keys.length;
|
|
24
|
+
// --- Note ---
|
|
25
|
+
// Meaning the next variation assignment won't add new experiment
|
|
26
|
+
// but rather overwrite the existing one
|
|
27
|
+
const isExclusive = keys.length === 1 && keys[0] === String(experimentId);
|
|
28
|
+
const isSatisfied = isEmpty || isExclusive;
|
|
29
|
+
return (0, _tsRes.Ok)(this.inverseResult ? !isSatisfied : isSatisfied);
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
32
|
exports.ExclusiveExperimentCondition = ExclusiveExperimentCondition;
|
|
21
33
|
//# sourceMappingURL=exclusiveExperimentCondition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclusiveExperimentCondition.js","
|
|
1
|
+
{"version":3,"file":"exclusiveExperimentCondition.js","names":["_tsRes","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ExclusiveExperimentCondition","constructor","isInclude","inverseResult","evaluate","experimentId","variationData","keys","isEmpty","length","isExclusive","isSatisfied","Ok","exports"],"sources":["../../../src/targeting/conditions/exclusiveExperimentCondition.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from '../../kameleoonError';\nimport { EvaluationDataType } from '../types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class ExclusiveExperimentCondition implements ICondition {\n private inverseResult: boolean;\n\n constructor({ isInclude }: ConditionDataType) {\n this.inverseResult = !(isInclude ?? true);\n }\n\n evaluate({\n experimentId,\n variationData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const keys = Object.keys(variationData);\n const isEmpty = !keys.length;\n // --- Note ---\n // Meaning the next variation assignment won't add new experiment\n // but rather overwrite the existing one\n const isExclusive = keys.length === 1 && keys[0] === String(experimentId);\n\n const isSatisfied = isEmpty || isExclusive;\n\n return Ok(this.inverseResult ? !isSatisfied : isSatisfied);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAoC,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAK7B,MAAMU,4BAA4B,CAAuB;EAG9DC,WAAWA,CAAC;IAAEC;EAA6B,CAAC,EAAE;IAAAzB,eAAA;IAC5C,IAAI,CAAC0B,aAAa,GAAG,EAAED,SAAS,IAAI,IAAI,CAAC;EAC3C;EAEAE,QAAQA,CAAC;IACPC,YAAY;IACZC;EACkB,CAAC,EAAmC;IACtD,MAAMC,IAAI,GAAGzB,MAAM,CAACyB,IAAI,CAACD,aAAa,CAAC;IACvC,MAAME,OAAO,GAAG,CAACD,IAAI,CAACE,MAAM;IAC5B;IACA;IACA;IACA,MAAMC,WAAW,GAAGH,IAAI,CAACE,MAAM,KAAK,CAAC,IAAIF,IAAI,CAAC,CAAC,CAAC,KAAKlB,MAAM,CAACgB,YAAY,CAAC;IAEzE,MAAMM,WAAW,GAAGH,OAAO,IAAIE,WAAW;IAE1C,OAAO,IAAAE,SAAE,EAAC,IAAI,CAACT,aAAa,GAAG,CAACQ,WAAW,GAAGA,WAAW,CAAC;EAC5D;AACF;AAACE,OAAA,CAAAb,4BAAA,GAAAA,4BAAA"}
|
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ConditionDataType", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _types.ConditionDataType;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ConditionFactory", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _conditionFactory.ConditionFactory;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ConditionType", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _types.ConditionType;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "CustomDataCondition", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _customDataCondition.CustomDataCondition;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "ExclusiveExperimentCondition", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _exclusiveExperimentCondition.ExclusiveExperimentCondition;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "TargetExperimentCondition", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _targetExperimentCondition.TargetExperimentCondition;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _conditionFactory = require("./conditionFactory");
|
|
43
|
+
var _types = require("./types");
|
|
44
|
+
var _customDataCondition = require("./customDataCondition");
|
|
45
|
+
var _targetExperimentCondition = require("./targetExperimentCondition");
|
|
46
|
+
var _exclusiveExperimentCondition = require("./exclusiveExperimentCondition");
|
|
12
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_conditionFactory","require","_types","_customDataCondition","_targetExperimentCondition","_exclusiveExperimentCondition"],"sources":["../../../src/targeting/conditions/index.ts"],"sourcesContent":["export { ConditionFactory } from './conditionFactory';\nexport { ConditionDataType, ConditionType } from './types';\nexport { CustomDataCondition } from './customDataCondition';\nexport { TargetExperimentCondition } from './targetExperimentCondition';\nexport { ExclusiveExperimentCondition } from './exclusiveExperimentCondition';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AACA,IAAAG,0BAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA"}
|