@kameleoon/javascript-sdk-core 2.4.5 → 2.5.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/cacheManager/cacheManager.js +3 -65
- package/dist/cacheManager/cacheManager.js.map +1 -1
- package/dist/cacheManager/index.js +1 -19
- package/dist/cacheManager/index.js.map +1 -1
- package/dist/cacheManager/types.js +1 -5
- package/dist/campaignConfiguration/campaignConfiguration.d.ts +7 -5
- package/dist/campaignConfiguration/campaignConfiguration.js +9 -283
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
- package/dist/campaignConfiguration/constants.d.ts +2 -10
- package/dist/campaignConfiguration/constants.js +2 -21
- package/dist/campaignConfiguration/constants.js.map +1 -1
- package/dist/campaignConfiguration/index.js +1 -86
- package/dist/campaignConfiguration/index.js.map +1 -1
- package/dist/campaignConfiguration/types.d.ts +7 -6
- package/dist/campaignConfiguration/types.js +1 -54
- package/dist/campaignConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +1 -1
- package/dist/clientSettings/clientSettings.js +1 -35
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/index.js +1 -19
- package/dist/clientSettings/index.js.map +1 -1
- package/dist/clientSettings/types.d.ts +1 -1
- package/dist/clientSettings/types.js +1 -5
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/constants.d.ts +13 -4
- package/dist/constants.js +2 -36
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/constants.js +1 -8
- package/dist/eventSource/constants.js.map +1 -1
- package/dist/eventSource/externalEventSource.js +1 -33
- package/dist/eventSource/externalEventSource.js.map +1 -1
- package/dist/eventSource/index.js +1 -50
- package/dist/eventSource/index.js.map +1 -1
- package/dist/eventSource/types.js +1 -5
- package/dist/hasher/hasher.js +6 -44
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/index.js +1 -12
- package/dist/hasher/index.js.map +1 -1
- package/dist/hasher/types.d.ts +1 -1
- package/dist/hasher/types.js +1 -5
- package/dist/hasher/types.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -310
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +16 -4
- package/dist/kameleoonClient.js +10 -384
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonData/browser.d.ts +8 -3
- package/dist/kameleoonData/browser.js +9 -40
- package/dist/kameleoonData/browser.js.map +1 -1
- package/dist/kameleoonData/conversion.d.ts +2 -2
- package/dist/kameleoonData/conversion.js +5 -50
- package/dist/kameleoonData/conversion.js.map +1 -1
- package/dist/kameleoonData/customData.d.ts +2 -2
- package/dist/kameleoonData/customData.js +5 -55
- package/dist/kameleoonData/customData.js.map +1 -1
- package/dist/kameleoonData/device.d.ts +2 -2
- package/dist/kameleoonData/device.js +5 -40
- package/dist/kameleoonData/device.js.map +1 -1
- package/dist/kameleoonData/index.d.ts +1 -1
- package/dist/kameleoonData/index.js +1 -102
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/pageView.d.ts +2 -2
- package/dist/kameleoonData/pageView.js +5 -56
- package/dist/kameleoonData/pageView.js.map +1 -1
- package/dist/kameleoonData/types.d.ts +44 -27
- package/dist/kameleoonData/types.js +6 -42
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonData/userAgent.d.ts +2 -2
- package/dist/kameleoonData/userAgent.js +4 -37
- package/dist/kameleoonData/userAgent.js.map +1 -1
- package/dist/kameleoonError/constants.d.ts +4 -2
- package/dist/kameleoonError/constants.js +1 -31
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/helpers.js +1 -9
- package/dist/kameleoonError/helpers.js.map +1 -1
- package/dist/kameleoonError/index.js +1 -26
- package/dist/kameleoonError/index.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.d.ts +3 -3
- package/dist/kameleoonError/kameleoonError.js +2 -75
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.d.ts +2 -0
- package/dist/kameleoonError/types.js +1 -31
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/kameleoonUtils.js +2 -44
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.js +4 -73
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.js +1 -80
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +4 -5
- package/dist/requester/requester.js +1 -106
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +8 -7
- package/dist/requester/types.js +1 -16
- package/dist/requester/types.js.map +1 -1
- package/dist/storage/constants.js +2 -15
- package/dist/storage/constants.js.map +1 -1
- package/dist/storage/externalStorage.d.ts +1 -1
- package/dist/storage/externalStorage.js +1 -40
- package/dist/storage/externalStorage.js.map +1 -1
- package/dist/storage/index.js +1 -56
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/types.d.ts +4 -4
- package/dist/storage/types.js +1 -5
- package/dist/storage/types.js.map +1 -1
- package/dist/targeting/conditions/browserCondition.d.ts +13 -0
- package/dist/targeting/conditions/browserCondition.js +2 -0
- package/dist/targeting/conditions/browserCondition.js.map +1 -0
- package/dist/targeting/conditions/conditionFactory.d.ts +1 -1
- package/dist/targeting/conditions/conditionFactory.js +1 -30
- package/dist/targeting/conditions/conditionFactory.js.map +1 -1
- package/dist/targeting/conditions/conversionCondition.d.ts +10 -0
- package/dist/targeting/conditions/conversionCondition.js +4 -0
- package/dist/targeting/conditions/conversionCondition.js.map +1 -0
- package/dist/targeting/conditions/customDataCondition.d.ts +5 -7
- package/dist/targeting/conditions/customDataCondition.js +7 -109
- package/dist/targeting/conditions/customDataCondition.js.map +1 -1
- package/dist/targeting/conditions/deviceCondition.d.ts +9 -0
- package/dist/targeting/conditions/deviceCondition.js +2 -0
- package/dist/targeting/conditions/deviceCondition.js.map +1 -0
- package/dist/targeting/conditions/exclusiveExperimentCondition.d.ts +3 -5
- package/dist/targeting/conditions/exclusiveExperimentCondition.js +1 -32
- package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/index.d.ts +7 -0
- package/dist/targeting/conditions/index.js +1 -46
- package/dist/targeting/conditions/index.js.map +1 -1
- package/dist/targeting/conditions/pageTitleCondition.d.ts +11 -0
- package/dist/targeting/conditions/pageTitleCondition.js +2 -0
- package/dist/targeting/conditions/pageTitleCondition.js.map +1 -0
- package/dist/targeting/conditions/pageUrlCondition.d.ts +11 -0
- package/dist/targeting/conditions/pageUrlCondition.js +2 -0
- package/dist/targeting/conditions/pageUrlCondition.js.map +1 -0
- package/dist/targeting/conditions/sdkLanguageCondition.d.ts +15 -0
- package/dist/targeting/conditions/sdkLanguageCondition.js +2 -0
- package/dist/targeting/conditions/sdkLanguageCondition.js.map +1 -0
- package/dist/targeting/conditions/targetExperimentCondition.d.ts +3 -4
- package/dist/targeting/conditions/targetExperimentCondition.js +1 -63
- package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/types.d.ts +25 -6
- package/dist/targeting/conditions/types.js +1 -5
- package/dist/targeting/conditions/types.js.map +1 -1
- package/dist/targeting/conditions/visitorCodeCondition.d.ts +11 -0
- package/dist/targeting/conditions/visitorCodeCondition.js +2 -0
- package/dist/targeting/conditions/visitorCodeCondition.js.map +1 -0
- package/dist/targeting/index.d.ts +2 -2
- package/dist/targeting/index.js +1 -80
- package/dist/targeting/index.js.map +1 -1
- package/dist/targeting/targetingNode.d.ts +3 -1
- package/dist/targeting/targetingNode.js +1 -47
- package/dist/targeting/targetingNode.js.map +1 -1
- package/dist/targeting/targetingTree.d.ts +3 -1
- package/dist/targeting/targetingTree.js +34 -135
- package/dist/targeting/targetingTree.js.map +1 -1
- package/dist/targeting/types.d.ts +24 -9
- package/dist/targeting/types.js +1 -100
- package/dist/targeting/types.js.map +1 -1
- package/dist/types.d.ts +9 -4
- package/dist/types.js +12 -41
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +1 -8
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +1 -12
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/types.d.ts +14 -7
- package/dist/utilities/types.js +1 -5
- package/dist/utilities/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +12 -8
- package/dist/utilities/utilities.js +1 -216
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/variationConfiguration/index.js +1 -25
- package/dist/variationConfiguration/index.js.map +1 -1
- package/dist/variationConfiguration/types.d.ts +5 -3
- package/dist/variationConfiguration/types.js +1 -5
- package/dist/variationConfiguration/types.js.map +1 -1
- package/dist/variationConfiguration/variation.d.ts +1 -1
- package/dist/variationConfiguration/variation.js +6 -44
- package/dist/variationConfiguration/variation.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.d.ts +4 -4
- package/dist/variationConfiguration/variationConfiguration.js +65 -290
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/package.json +1 -1
- package/dist/kameleoonData/constants.d.ts +0 -1
- package/dist/kameleoonData/constants.js +0 -9
- package/dist/kameleoonData/constants.js.map +0 -1
- package/dist/kameleoonData/nonce.d.ts +0 -5
- package/dist/kameleoonData/nonce.js +0 -32
- package/dist/kameleoonData/nonce.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { FeatureFlagType, RuleItemType } from '
|
|
2
|
-
import {
|
|
1
|
+
import { FeatureFlagType, RuleItemType } from 'src/campaignConfiguration';
|
|
2
|
+
import { KameleoonVisitorDataType } from 'src/kameleoonData/types';
|
|
3
|
+
import { ExternalPackageInfoType } from 'src/types';
|
|
3
4
|
export type VariationType = {
|
|
4
5
|
variationId: number;
|
|
5
6
|
assignmentDate: string;
|
|
@@ -20,6 +21,7 @@ export type FeatureFlagVariationType = {
|
|
|
20
21
|
export type GetFeatureFlagVariationParametersType = {
|
|
21
22
|
visitorCode: string;
|
|
22
23
|
featureFlag: FeatureFlagType;
|
|
23
|
-
targetingData
|
|
24
|
+
targetingData: KameleoonVisitorDataType;
|
|
24
25
|
withAssignment?: boolean;
|
|
26
|
+
packageInfo: ExternalPackageInfoType;
|
|
25
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/variationConfiguration/types.ts"],"sourcesContent":["import { FeatureFlagType, RuleItemType } from '
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/variationConfiguration/types.ts"],"sourcesContent":["import { FeatureFlagType, RuleItemType } from 'src/campaignConfiguration';\nimport { KameleoonVisitorDataType } from 'src/kameleoonData/types';\nimport { ExternalPackageInfoType } from 'src/types';\n\nexport type VariationType = {\n variationId: number;\n assignmentDate: string;\n};\n\nexport type UpdateStorageParamsType = {\n visitorCode: string;\n experimentId: string;\n variationId: number;\n};\n\nexport type FeatureFlagVariationType = {\n variationKey: string;\n variationId: number | null;\n experimentId: number | null;\n featureFlagId: number;\n featureKey: string;\n rule: RuleItemType | null;\n};\n\nexport type GetFeatureFlagVariationParametersType = {\n visitorCode: string;\n featureFlag: FeatureFlagType;\n targetingData: KameleoonVisitorDataType;\n withAssignment?: boolean;\n packageInfo: ExternalPackageInfoType;\n};\n"],"mappings":""}
|
|
@@ -1,45 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _types = require("../types");
|
|
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); }
|
|
11
|
-
class Variation {
|
|
12
|
-
constructor(variationData) {
|
|
13
|
-
_defineProperty(this, "variationData", void 0);
|
|
14
|
-
this.variationData = variationData;
|
|
15
|
-
}
|
|
16
|
-
get id() {
|
|
17
|
-
if (!this.variationData) {
|
|
18
|
-
throw new Error("Internal usage error: Check if the variation `isValid`, before getting it's `id`");
|
|
19
|
-
}
|
|
20
|
-
return this.variationData.variationId;
|
|
21
|
-
}
|
|
22
|
-
isValid(respoolTime) {
|
|
23
|
-
const variation = this.variationData;
|
|
24
|
-
if (!variation) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// --- Note ---
|
|
29
|
-
// - Respool is a kind of shuffle parameter
|
|
30
|
-
// it's presence indicates that variations assigned to
|
|
31
|
-
// user has changed at certain time (time is the value of `respoolTime` in seconds)
|
|
32
|
-
// - So the variation is valid unless it has been shuffled after it's assignment
|
|
33
|
-
if (respoolTime?.length) {
|
|
34
|
-
const assignmentTime = new Date(Date.parse(variation.assignmentDate)).getTime() / _types.Milliseconds.Second;
|
|
35
|
-
const variationRespoolTime = respoolTime.find(respool => respool.variationId === String(variation.variationId));
|
|
36
|
-
if (!variationRespoolTime) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return assignmentTime > variationRespoolTime.value;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Variation = Variation;
|
|
1
|
+
"use strict";var _types=require("../types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Variation=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var Variation=/*#__PURE__*/function(){function a(b){_classCallCheck(this,a),_defineProperty(this,"variationData",void 0),this.variationData=b}return _createClass(a,[{key:"id",get:function get(){if(!this.variationData)throw new Error("Internal usage error: Check if the variation `isValid`, before getting it's `id`");return this.variationData.variationId}},{key:"isValid",value:function isValid(a){var b=this.variationData;if(!b)return!1;// --- Note ---
|
|
2
|
+
// - Respool is a kind of shuffle parameter
|
|
3
|
+
// it's presence indicates that variations assigned to
|
|
4
|
+
// user has changed at certain time (time is the value of `respoolTime` in seconds)
|
|
5
|
+
// - So the variation is valid unless it has been shuffled after it's assignment
|
|
6
|
+
if(null!==a&&void 0!==a&&a.length){var c=new Date(Date.parse(b.assignmentDate)).getTime()/_types.Milliseconds.Second,d=a.find(function(a){return a.variationId===b.variationId+""});return!d||c>d.value}return!0}}]),a}();exports.Variation=Variation;
|
|
45
7
|
//# sourceMappingURL=variation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variation.js","names":["_types","require","
|
|
1
|
+
{"version":3,"file":"variation.js","names":["_types","require","Object","defineProperty","exports","value","Variation","_typeof","a","Symbol","iterator","constructor","prototype","_classCallCheck","b","TypeError","_defineProperties","c","d","length","enumerable","configurable","writable","_toPropertyKey","key","_createClass","_defineProperty","_toPrimitive","toPrimitive","call","String","Number","variationData","get","Error","variationId","isValid","respoolTime","variation","assignmentTime","Date","parse","assignmentDate","getTime","Milliseconds","Second","variationRespoolTime","find","respool"],"sources":["../../src/variationConfiguration/variation.ts"],"sourcesContent":["import { RespoolTimeType } from 'src/campaignConfiguration/types';\nimport { Milliseconds } from 'src/types';\nimport { VariationType } from './types';\n\ninterface IVariation {\n readonly id: number;\n isValid: (respoolTime?: RespoolTimeType[]) => boolean;\n}\n\nexport class Variation implements IVariation {\n variationData?: VariationType;\n\n constructor(variationData?: VariationType) {\n this.variationData = variationData;\n }\n\n get id(): number {\n if (!this.variationData) {\n throw new Error(\n \"Internal usage error: Check if the variation `isValid`, before getting it's `id`\",\n );\n }\n\n return this.variationData.variationId;\n }\n\n public isValid(respoolTime?: RespoolTimeType[]): boolean {\n const variation = this.variationData;\n\n if (!variation) {\n return false;\n }\n\n // --- Note ---\n // - Respool is a kind of shuffle parameter\n // it's presence indicates that variations assigned to\n // user has changed at certain time (time is the value of `respoolTime` in seconds)\n // - So the variation is valid unless it has been shuffled after it's assignment\n if (respoolTime?.length) {\n const assignmentTime =\n new Date(Date.parse(variation.assignmentDate)).getTime() /\n Milliseconds.Second;\n const variationRespoolTime = respoolTime.find(\n (respool) => respool.variationId === String(variation.variationId),\n );\n\n if (!variationRespoolTime) {\n return true;\n }\n\n return assignmentTime > variationRespoolTime.value;\n }\n\n return true;\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Result } from 'ts-res';
|
|
2
|
-
import { ExperimentItemType } from '
|
|
3
|
-
import { KameleoonError } from '
|
|
4
|
-
import { IStorage, VariationDataType, ExperimentVariationsType } from '
|
|
2
|
+
import { ExperimentItemType } from 'src/campaignConfiguration';
|
|
3
|
+
import { KameleoonError } from 'src/kameleoonError';
|
|
4
|
+
import { IStorage, VariationDataType, ExperimentVariationsType } from 'src/storage';
|
|
5
5
|
import { FeatureFlagVariationType, GetFeatureFlagVariationParametersType } from './types';
|
|
6
6
|
interface IVariationConfiguration {
|
|
7
7
|
/**
|
|
@@ -27,7 +27,7 @@ export declare class VariationConfiguration implements IVariationConfiguration {
|
|
|
27
27
|
constructor(experiments: ExperimentItemType[], externalStorage: IStorage<VariationDataType>);
|
|
28
28
|
getAssociatedVariationId: (visitorCode: string, experimentId: number) => Result<number, KameleoonError>;
|
|
29
29
|
getAssignedVariations(visitorCode: string): Result<ExperimentVariationsType, KameleoonError>;
|
|
30
|
-
getFeatureFlagVariation({ visitorCode, featureFlag, targetingData, withAssignment, }: GetFeatureFlagVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>;
|
|
30
|
+
getFeatureFlagVariation({ visitorCode, featureFlag, targetingData, packageInfo, withAssignment, }: GetFeatureFlagVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>;
|
|
31
31
|
getExperimentVariation(visitorCode: string, experiment: ExperimentItemType): Result<number, KameleoonError>;
|
|
32
32
|
private assignVariation;
|
|
33
33
|
private updateStorageData;
|
|
@@ -1,291 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
featureFlag,
|
|
67
|
-
targetingData,
|
|
68
|
-
withAssignment = false
|
|
69
|
-
}) {
|
|
70
|
-
const validateResult = _utilities.Utilities.validateVisitorCode(visitorCode);
|
|
71
|
-
if (!validateResult.ok) {
|
|
72
|
-
return (0, _tsRes.Err)(validateResult.error);
|
|
73
|
-
}
|
|
74
|
-
const {
|
|
75
|
-
rules,
|
|
76
|
-
featureKey,
|
|
77
|
-
id: featureFlagId,
|
|
78
|
-
defaultVariationKey
|
|
79
|
-
} = featureFlag;
|
|
80
|
-
for (const rule of rules) {
|
|
81
|
-
const {
|
|
82
|
-
segment,
|
|
83
|
-
experimentId,
|
|
84
|
-
id,
|
|
85
|
-
exposition,
|
|
86
|
-
respoolTime,
|
|
87
|
-
variationByExposition
|
|
88
|
-
} = rule;
|
|
89
|
-
|
|
90
|
-
// --- Check targeting ---
|
|
91
|
-
const targetingResult = _utilities.Utilities.checkTargeting({
|
|
92
|
-
segment,
|
|
93
|
-
visitorCode,
|
|
94
|
-
experimentId,
|
|
95
|
-
targetingData,
|
|
96
|
-
variationConfiguration: this
|
|
97
|
-
});
|
|
98
|
-
if (!targetingResult.ok) {
|
|
99
|
-
return targetingResult;
|
|
100
|
-
}
|
|
101
|
-
if (!targetingResult.data) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// --- Note ---
|
|
106
|
-
// Calculate new variation (and assign it if `withAssignment` is `true`)
|
|
107
|
-
// First the the exposed rule is calculated and then the variation inside of it
|
|
108
|
-
const ruleHash = _hasher.Hasher.obtainFeatureFlagHashDouble({
|
|
109
|
-
visitorCode,
|
|
110
|
-
respoolTime,
|
|
111
|
-
campaignId: String(id)
|
|
112
|
-
});
|
|
113
|
-
if (ruleHash <= exposition) {
|
|
114
|
-
let totalDeviation = 0;
|
|
115
|
-
const variationHash = _hasher.Hasher.obtainFeatureFlagHashDouble({
|
|
116
|
-
visitorCode,
|
|
117
|
-
respoolTime,
|
|
118
|
-
campaignId: String(experimentId)
|
|
119
|
-
});
|
|
120
|
-
for (const variation of variationByExposition) {
|
|
121
|
-
totalDeviation += variation.exposition;
|
|
122
|
-
if (variationHash <= totalDeviation) {
|
|
123
|
-
// --- Note ---
|
|
124
|
-
// For the `RuleType.EXPERIMENTATION` variation assignment must happen without
|
|
125
|
-
// calculating experiment deviation
|
|
126
|
-
if (rule.type === _types.RuleType.EXPERIMENTATION && withAssignment) {
|
|
127
|
-
this.updateStorageData({
|
|
128
|
-
visitorCode,
|
|
129
|
-
experimentId: String(experimentId),
|
|
130
|
-
// --- Note ---
|
|
131
|
-
// For `RuleType.EXPERIMENTATION` `variationId` can not be null
|
|
132
|
-
variationId: variation.variationId
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
const {
|
|
136
|
-
exposition
|
|
137
|
-
} = variation,
|
|
138
|
-
restParameters = _objectWithoutProperties(variation, _excluded);
|
|
139
|
-
return (0, _tsRes.Ok)(_objectSpread(_objectSpread({}, restParameters), {}, {
|
|
140
|
-
rule,
|
|
141
|
-
featureFlagId,
|
|
142
|
-
featureKey,
|
|
143
|
-
experimentId
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (rule.type === _types.RuleType.TARGETED_DELIVERY) {
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return (0, _tsRes.Ok)({
|
|
153
|
-
featureKey,
|
|
154
|
-
featureFlagId,
|
|
155
|
-
experimentId: null,
|
|
156
|
-
variationKey: defaultVariationKey,
|
|
157
|
-
variationId: null,
|
|
158
|
-
rule: null
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
getExperimentVariation(visitorCode, experiment) {
|
|
162
|
-
const {
|
|
163
|
-
id,
|
|
164
|
-
respoolTime,
|
|
165
|
-
deviations
|
|
166
|
-
} = experiment;
|
|
167
|
-
const hashDouble = _hasher.Hasher.obtainExperimentHashDouble({
|
|
168
|
-
visitorCode,
|
|
169
|
-
campaignId: id,
|
|
170
|
-
respoolTime
|
|
171
|
-
});
|
|
172
|
-
let isUnallocated = true;
|
|
173
|
-
let totalDeviation = 0;
|
|
174
|
-
let resultVariationId = 0;
|
|
175
|
-
for (const deviation of deviations) {
|
|
176
|
-
totalDeviation += deviation.value;
|
|
177
|
-
if (totalDeviation >= hashDouble) {
|
|
178
|
-
// --- Note ---
|
|
179
|
-
// If sum of all variations is less than 1 (100%), then there is a chance
|
|
180
|
-
// user will end up outside of any variation
|
|
181
|
-
isUnallocated = false;
|
|
182
|
-
// --- Note ---
|
|
183
|
-
// 'origin' is the default `variationId`, it must return id of 0
|
|
184
|
-
if (deviation.variationId !== 'origin') {
|
|
185
|
-
resultVariationId = Number(deviation.variationId);
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (isUnallocated) {
|
|
191
|
-
return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NotAllocated, visitorCode));
|
|
192
|
-
}
|
|
193
|
-
return (0, _tsRes.Ok)(resultVariationId);
|
|
194
|
-
}
|
|
195
|
-
assignVariation(visitorCode, experiment) {
|
|
196
|
-
const variationResult = this.getExperimentVariation(visitorCode, experiment);
|
|
197
|
-
if (!variationResult.ok) {
|
|
198
|
-
return variationResult;
|
|
199
|
-
}
|
|
200
|
-
const result = this.updateStorageData({
|
|
201
|
-
visitorCode,
|
|
202
|
-
experimentId: experiment.id,
|
|
203
|
-
variationId: variationResult.data
|
|
204
|
-
});
|
|
205
|
-
if (!result.ok) {
|
|
206
|
-
return result;
|
|
207
|
-
}
|
|
208
|
-
return (0, _tsRes.Ok)(variationResult.data);
|
|
209
|
-
}
|
|
210
|
-
updateStorageData({
|
|
211
|
-
visitorCode,
|
|
212
|
-
experimentId,
|
|
213
|
-
variationId
|
|
214
|
-
}) {
|
|
215
|
-
const result = this.storage.read();
|
|
216
|
-
if (!result.ok) {
|
|
217
|
-
// --- Note ---
|
|
218
|
-
// If there is a parsing error we return error
|
|
219
|
-
// But if there is `LocalStorageRead` error it means that
|
|
220
|
-
// data was read successfully and it's empty, which is not problem
|
|
221
|
-
// cause that might be initial `read`
|
|
222
|
-
if (result.error.type === _kameleoonError.KameleoonException.StorageParse) {
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
const updatedVariationData = result.ok ? result.data : {};
|
|
227
|
-
const updatedVariation = {
|
|
228
|
-
variationId,
|
|
229
|
-
assignmentDate: new Date().toString()
|
|
230
|
-
};
|
|
231
|
-
if (updatedVariationData[visitorCode]) {
|
|
232
|
-
updatedVariationData[visitorCode][experimentId] = updatedVariation;
|
|
233
|
-
} else {
|
|
234
|
-
updatedVariationData[visitorCode] = {
|
|
235
|
-
[experimentId]: updatedVariation
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return this.storage.write(updatedVariationData);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// --- TODO: commented out in case of future logic rework ---
|
|
242
|
-
// --- Mind: `variationId` could cause the `undefined` issue ---
|
|
243
|
-
// --- Reference: https://development.kameleoon.net/sdk/javascript-sdk-packages/-/merge_requests/89 ---
|
|
244
|
-
// private getAssignedRuleVariation(
|
|
245
|
-
// visitorCode: string,
|
|
246
|
-
// rule: RuleItemType,
|
|
247
|
-
// ): Result<GetAssignedRuleVariationResultType, KameleoonError> {
|
|
248
|
-
// const emptyVariation: Omit<VariationByExpositionType, 'exposition'> = {
|
|
249
|
-
// variationId: null,
|
|
250
|
-
// variationKey: '',
|
|
251
|
-
// };
|
|
252
|
-
// const { experimentId, variationByExposition } = rule;
|
|
253
|
-
|
|
254
|
-
// const variationsResult = this.getAssignedVariations(visitorCode);
|
|
255
|
-
|
|
256
|
-
// // --- Note ---
|
|
257
|
-
// // If there is an error, we just want to skip seeking
|
|
258
|
-
// // for variation in the storage, not throw an error
|
|
259
|
-
// if (!variationsResult.ok) {
|
|
260
|
-
// return Ok(emptyVariation);
|
|
261
|
-
// }
|
|
262
|
-
|
|
263
|
-
// const variations = variationsResult.data;
|
|
264
|
-
|
|
265
|
-
// if (
|
|
266
|
-
// experimentId &&
|
|
267
|
-
// typeof variations[experimentId].variationId !== undefined
|
|
268
|
-
// ) {
|
|
269
|
-
// const id = variations[experimentId].variationId;
|
|
270
|
-
// const featureFlagVariation = variationByExposition.find(
|
|
271
|
-
// (item) => item.variationId == id,
|
|
272
|
-
// );
|
|
273
|
-
|
|
274
|
-
// if (!featureFlagVariation) {
|
|
275
|
-
// // --- Note ---
|
|
276
|
-
// // This error is not described for public methods as
|
|
277
|
-
// // it serves internal purpose of checking whether
|
|
278
|
-
// // the persistent variation has been updated and should be re-allocated
|
|
279
|
-
// return Err(new KameleoonError(KameleoonException.DataInconsistency));
|
|
280
|
-
// }
|
|
281
|
-
|
|
282
|
-
// const { exposition, ...restParameters } = featureFlagVariation;
|
|
283
|
-
|
|
284
|
-
// return Ok({ ...restParameters });
|
|
285
|
-
// }
|
|
286
|
-
|
|
287
|
-
// return Ok(emptyVariation);
|
|
288
|
-
// }
|
|
289
|
-
}
|
|
290
|
-
exports.VariationConfiguration = VariationConfiguration;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariationConfiguration=void 0;var _tsRes=require("ts-res"),_hasher=require("../hasher"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_types=require("../campaignConfiguration/types"),_excluded=["exposition"];function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var VariationConfiguration=/*#__PURE__*/function(){function a(b,c){var d=this;_classCallCheck(this,a),_defineProperty(this,"experiments",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"getAssociatedVariationId",function(a,b){// TODO:
|
|
2
|
+
// --- Variation from storage is not checked anymore
|
|
3
|
+
// --- If nothing changes the commented code should be deleted
|
|
4
|
+
// along with the `Variation` class and according tests/types
|
|
5
|
+
// --- Mind `todo` in `getAssociatedVariationId.spec.ts`
|
|
6
|
+
//
|
|
7
|
+
// let associatedVariation: VariationType | undefined;
|
|
8
|
+
// this.storage.read().and((data) => {
|
|
9
|
+
// associatedVariation = data?.[visitorCode]?.[experimentId];
|
|
10
|
+
// });
|
|
11
|
+
var c=d.experiments.find(function(a){return a.id===b+""});return c?d.assignVariation(a,c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ExperimentConfigurationNotFound,b,a));// const variation = new Variation(associatedVariation);
|
|
12
|
+
// if (variation.isValid(experiment?.respoolTime)) {
|
|
13
|
+
// return Ok(variation.id);
|
|
14
|
+
// }
|
|
15
|
+
}),this.experiments=b,this.storage=c}return _createClass(a,[{key:"getAssignedVariations",value:function getAssignedVariations(a){var b=this.storage.read();if(!b.ok)return b;var c=b.data[a];return c?(0,_tsRes.Ok)(c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageRead,a))}},{key:"getFeatureFlagVariation",value:function getFeatureFlagVariation(a){var b=a.visitorCode,c=a.featureFlag,d=a.targetingData,e=a.packageInfo,f=a.withAssignment,g=_utilities.Utilities.validateVisitorCode(b);if(!g.ok)return(0,_tsRes.Err)(g.error);var h,i=c.rules,j=c.featureKey,k=c.id,l=c.defaultVariationKey,m=_createForOfIteratorHelper(i);try{for(m.s();!(h=m.n()).done;){var n=h.value,o=n.segment,p=n.experimentId,q=n.id,r=n.exposition,s=n.respoolTime,t=n.variationByExposition,u=_utilities.Utilities.checkTargeting({segment:o,visitorCode:b,experimentId:p,targetingData:d,packageInfo:e,variationConfiguration:this});if(!u.ok)return u;if(u.data){// --- Note ---
|
|
16
|
+
// Calculate new variation (and assign it if `withAssignment` is `true`)
|
|
17
|
+
// First the the exposed rule is calculated and then the variation inside of it
|
|
18
|
+
var v=_hasher.Hasher.obtainFeatureFlagHashDouble({visitorCode:b,respoolTime:s,campaignId:q+""});if(v<=r){var w,x=0,y=_hasher.Hasher.obtainFeatureFlagHashDouble({visitorCode:b,respoolTime:s,campaignId:p+""}),z=_createForOfIteratorHelper(t);try{for(z.s();!(w=z.n()).done;){var A=w.value;if(x+=A.exposition,y<=x){n.type===_types.RuleType.EXPERIMENTATION&&void 0!==f&&f&&this.updateStorageData({visitorCode:b,experimentId:p+"",// --- Note ---
|
|
19
|
+
// For `RuleType.EXPERIMENTATION` `variationId` can not be null
|
|
20
|
+
variationId:A.variationId});var B=A.exposition,C=_objectWithoutProperties(A,_excluded);return(0,_tsRes.Ok)(_objectSpread(_objectSpread({},C),{},{rule:n,featureFlagId:k,featureKey:j,experimentId:p}))}}}catch(a){z.e(a)}finally{z.f()}}if(n.type===_types.RuleType.TARGETED_DELIVERY)break}}}catch(a){m.e(a)}finally{m.f()}return(0,_tsRes.Ok)({featureKey:j,featureFlagId:k,experimentId:null,variationKey:l,variationId:null,rule:null})}},{key:"getExperimentVariation",value:function getExperimentVariation(a,b){var c,d=b.id,e=b.respoolTime,f=b.deviations,g=_hasher.Hasher.obtainExperimentHashDouble({visitorCode:a,campaignId:d,respoolTime:e}),h=!0,i=0,j=0,k=_createForOfIteratorHelper(f);try{for(k.s();!(c=k.n()).done;){var l=c.value;if(i+=l.value,i>=g){h=!1,"origin"!==l.variationId&&(j=+l.variationId);break}}}catch(a){k.e(a)}finally{k.f()}return h?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NotAllocated,a)):(0,_tsRes.Ok)(j)}},{key:"assignVariation",value:function assignVariation(a,b){var c=this.getExperimentVariation(a,b);if(!c.ok)return c;var d=this.updateStorageData({visitorCode:a,experimentId:b.id,variationId:c.data});return d.ok?(0,_tsRes.Ok)(c.data):d}},{key:"updateStorageData",value:function updateStorageData(a){var b=a.visitorCode,c=a.experimentId,d=a.variationId,e=this.storage.read();if(!e.ok&&e.error.type===_kameleoonError.KameleoonException.StorageParse)// --- Note ---
|
|
21
|
+
// If there is a parsing error we return error
|
|
22
|
+
// But if there is `LocalStorageRead` error it means that
|
|
23
|
+
// data was read successfully and it's empty, which is not problem
|
|
24
|
+
// cause that might be initial `read`
|
|
25
|
+
return e;var f=e.ok?e.data:{},g={variationId:d,assignmentDate:new Date().toString()};return f[b]?f[b][c]=g:f[b]=_defineProperty({},c,g),this.storage.write(f)}// --- TODO: commented out in case of future logic rework ---
|
|
26
|
+
// --- Mind: `variationId` could cause the `undefined` issue ---
|
|
27
|
+
// --- Reference: https://development.kameleoon.net/sdk/javascript-sdk-packages/-/merge_requests/89 ---
|
|
28
|
+
// private getAssignedRuleVariation(
|
|
29
|
+
// visitorCode: string,
|
|
30
|
+
// rule: RuleItemType,
|
|
31
|
+
// ): Result<GetAssignedRuleVariationResultType, KameleoonError> {
|
|
32
|
+
// const emptyVariation: Omit<VariationByExpositionType, 'exposition'> = {
|
|
33
|
+
// variationId: null,
|
|
34
|
+
// variationKey: '',
|
|
35
|
+
// };
|
|
36
|
+
// const { experimentId, variationByExposition } = rule;
|
|
37
|
+
// const variationsResult = this.getAssignedVariations(visitorCode);
|
|
38
|
+
// // --- Note ---
|
|
39
|
+
// // If there is an error, we just want to skip seeking
|
|
40
|
+
// // for variation in the storage, not throw an error
|
|
41
|
+
// if (!variationsResult.ok) {
|
|
42
|
+
// return Ok(emptyVariation);
|
|
43
|
+
// }
|
|
44
|
+
// const variations = variationsResult.data;
|
|
45
|
+
// if (
|
|
46
|
+
// experimentId &&
|
|
47
|
+
// typeof variations[experimentId].variationId !== undefined
|
|
48
|
+
// ) {
|
|
49
|
+
// const id = variations[experimentId].variationId;
|
|
50
|
+
// const featureFlagVariation = variationByExposition.find(
|
|
51
|
+
// (item) => item.variationId == id,
|
|
52
|
+
// );
|
|
53
|
+
// if (!featureFlagVariation) {
|
|
54
|
+
// // --- Note ---
|
|
55
|
+
// // This error is not described for public methods as
|
|
56
|
+
// // it serves internal purpose of checking whether
|
|
57
|
+
// // the persistent variation has been updated and should be re-allocated
|
|
58
|
+
// return Err(new KameleoonError(KameleoonException.DataInconsistency));
|
|
59
|
+
// }
|
|
60
|
+
// const { exposition, ...restParameters } = featureFlagVariation;
|
|
61
|
+
// return Ok({ ...restParameters });
|
|
62
|
+
// }
|
|
63
|
+
// return Ok(emptyVariation);
|
|
64
|
+
// }
|
|
65
|
+
}]),a}();exports.VariationConfiguration=VariationConfiguration;
|
|
291
66
|
//# sourceMappingURL=variationConfiguration.js.map
|