@featurevisor/sdk 0.36.0 → 0.38.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/CHANGELOG.md +22 -0
- package/README.md +14 -14
- package/coverage/clover.xml +378 -315
- package/coverage/coverage-final.json +7 -7
- package/coverage/lcov-report/bucket.ts.html +4 -4
- package/coverage/lcov-report/conditions.ts.html +38 -38
- package/coverage/lcov-report/datafileReader.ts.html +4 -4
- package/coverage/lcov-report/emitter.ts.html +1 -1
- package/coverage/lcov-report/feature.ts.html +80 -20
- package/coverage/lcov-report/index.html +28 -28
- package/coverage/lcov-report/instance.ts.html +754 -220
- package/coverage/lcov-report/logger.ts.html +3 -3
- package/coverage/lcov-report/segments.ts.html +12 -12
- package/coverage/lcov.info +661 -559
- package/dist/index.js +1 -1
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/lib/conditions.d.ts +3 -3
- package/lib/conditions.js +35 -35
- package/lib/conditions.js.map +1 -1
- package/lib/feature.d.ts +4 -3
- package/lib/feature.js +13 -5
- package/lib/feature.js.map +1 -1
- package/lib/instance.d.ts +36 -27
- package/lib/instance.js +289 -148
- package/lib/instance.js.map +1 -1
- package/lib/segments.d.ts +3 -3
- package/lib/segments.js +8 -8
- package/lib/segments.js.map +1 -1
- package/package.json +3 -3
- package/src/conditions.ts +37 -37
- package/src/feature.ts +26 -6
- package/src/instance.spec.ts +64 -61
- package/src/instance.ts +325 -147
- package/src/segments.ts +9 -9
package/lib/conditions.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function conditionIsMatched(condition: PlainCondition,
|
|
3
|
-
export declare function allConditionsAreMatched(conditions: Condition[] | Condition,
|
|
1
|
+
import { Context, Condition, PlainCondition } from "@featurevisor/types";
|
|
2
|
+
export declare function conditionIsMatched(condition: PlainCondition, context: Context): boolean;
|
|
3
|
+
export declare function allConditionsAreMatched(conditions: Condition[] | Condition, context: Context): boolean;
|
package/lib/conditions.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
1
|
import { compareVersions } from "compare-versions";
|
|
2
|
-
export function conditionIsMatched(condition,
|
|
2
|
+
export function conditionIsMatched(condition, context) {
|
|
3
3
|
var attribute = condition.attribute, operator = condition.operator, value = condition.value;
|
|
4
4
|
if (operator === "equals") {
|
|
5
|
-
return
|
|
5
|
+
return context[attribute] === value;
|
|
6
6
|
}
|
|
7
7
|
else if (operator === "notEquals") {
|
|
8
|
-
return
|
|
8
|
+
return context[attribute] !== value;
|
|
9
9
|
}
|
|
10
10
|
else if (operator === "before" || operator === "after") {
|
|
11
11
|
// date comparisons
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var valueInContext = context[attribute];
|
|
13
|
+
var dateInContext = valueInContext instanceof Date ? valueInContext : new Date(valueInContext);
|
|
14
14
|
var dateInCondition = value instanceof Date ? value : new Date(value);
|
|
15
15
|
return operator === "before"
|
|
16
|
-
?
|
|
17
|
-
:
|
|
16
|
+
? dateInContext < dateInCondition
|
|
17
|
+
: dateInContext > dateInCondition;
|
|
18
18
|
}
|
|
19
|
-
else if (typeof
|
|
19
|
+
else if (typeof context[attribute] === "string" && Array.isArray(value)) {
|
|
20
20
|
// array
|
|
21
|
-
var
|
|
21
|
+
var valueInContext = context[attribute];
|
|
22
22
|
if (operator === "in") {
|
|
23
|
-
return value.indexOf(
|
|
23
|
+
return value.indexOf(valueInContext) !== -1;
|
|
24
24
|
}
|
|
25
25
|
else if (operator === "notIn") {
|
|
26
|
-
return value.indexOf(
|
|
26
|
+
return value.indexOf(valueInContext) === -1;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
else if (typeof
|
|
29
|
+
else if (typeof context[attribute] === "string" && typeof value === "string") {
|
|
30
30
|
// string
|
|
31
|
-
var
|
|
31
|
+
var valueInContext = context[attribute];
|
|
32
32
|
if (operator === "contains") {
|
|
33
|
-
return
|
|
33
|
+
return valueInContext.indexOf(value) !== -1;
|
|
34
34
|
}
|
|
35
35
|
else if (operator === "notContains") {
|
|
36
|
-
return
|
|
36
|
+
return valueInContext.indexOf(value) === -1;
|
|
37
37
|
}
|
|
38
38
|
else if (operator === "startsWith") {
|
|
39
|
-
return
|
|
39
|
+
return valueInContext.startsWith(value);
|
|
40
40
|
}
|
|
41
41
|
else if (operator === "endsWith") {
|
|
42
|
-
return
|
|
42
|
+
return valueInContext.endsWith(value);
|
|
43
43
|
}
|
|
44
44
|
else if (operator === "semverEquals") {
|
|
45
|
-
return compareVersions(
|
|
45
|
+
return compareVersions(valueInContext, value) === 0;
|
|
46
46
|
}
|
|
47
47
|
else if (operator === "semverNotEquals") {
|
|
48
|
-
return compareVersions(
|
|
48
|
+
return compareVersions(valueInContext, value) !== 0;
|
|
49
49
|
}
|
|
50
50
|
else if (operator === "semverGreaterThan") {
|
|
51
|
-
return compareVersions(
|
|
51
|
+
return compareVersions(valueInContext, value) === 1;
|
|
52
52
|
}
|
|
53
53
|
else if (operator === "semverGreaterThanOrEquals") {
|
|
54
|
-
return compareVersions(
|
|
54
|
+
return compareVersions(valueInContext, value) >= 0;
|
|
55
55
|
}
|
|
56
56
|
else if (operator === "semverLessThan") {
|
|
57
|
-
return compareVersions(
|
|
57
|
+
return compareVersions(valueInContext, value) === -1;
|
|
58
58
|
}
|
|
59
59
|
else if (operator === "semverLessThanOrEquals") {
|
|
60
|
-
return compareVersions(
|
|
60
|
+
return compareVersions(valueInContext, value) <= 0;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
else if (typeof
|
|
63
|
+
else if (typeof context[attribute] === "number" && typeof value === "number") {
|
|
64
64
|
// numeric
|
|
65
|
-
var
|
|
65
|
+
var valueInContext = context[attribute];
|
|
66
66
|
if (operator === "greaterThan") {
|
|
67
|
-
return
|
|
67
|
+
return valueInContext > value;
|
|
68
68
|
}
|
|
69
69
|
else if (operator === "greaterThanOrEquals") {
|
|
70
|
-
return
|
|
70
|
+
return valueInContext >= value;
|
|
71
71
|
}
|
|
72
72
|
else if (operator === "lessThan") {
|
|
73
|
-
return
|
|
73
|
+
return valueInContext < value;
|
|
74
74
|
}
|
|
75
75
|
else if (operator === "lessThanOrEquals") {
|
|
76
|
-
return
|
|
76
|
+
return valueInContext <= value;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
|
-
export function allConditionsAreMatched(conditions,
|
|
81
|
+
export function allConditionsAreMatched(conditions, context) {
|
|
82
82
|
if ("attribute" in conditions) {
|
|
83
|
-
return conditionIsMatched(conditions,
|
|
83
|
+
return conditionIsMatched(conditions, context);
|
|
84
84
|
}
|
|
85
85
|
if ("and" in conditions && Array.isArray(conditions.and)) {
|
|
86
|
-
return conditions.and.every(function (c) { return allConditionsAreMatched(c,
|
|
86
|
+
return conditions.and.every(function (c) { return allConditionsAreMatched(c, context); });
|
|
87
87
|
}
|
|
88
88
|
if ("or" in conditions && Array.isArray(conditions.or)) {
|
|
89
|
-
return conditions.or.some(function (c) { return allConditionsAreMatched(c,
|
|
89
|
+
return conditions.or.some(function (c) { return allConditionsAreMatched(c, context); });
|
|
90
90
|
}
|
|
91
91
|
if ("not" in conditions && Array.isArray(conditions.not)) {
|
|
92
92
|
return conditions.not.every(function (c) {
|
|
93
93
|
return allConditionsAreMatched({
|
|
94
94
|
and: conditions.not,
|
|
95
|
-
},
|
|
95
|
+
}, context) === false;
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
if (Array.isArray(conditions)) {
|
|
99
|
-
return conditions.every(function (c) { return allConditionsAreMatched(c,
|
|
99
|
+
return conditions.every(function (c) { return allConditionsAreMatched(c, context); });
|
|
100
100
|
}
|
|
101
101
|
return false;
|
|
102
102
|
}
|
package/lib/conditions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAA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EAAE,CAAC,EAAE;QACtD,OAAO,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,EAAnC,CAAmC,CAAC,CAAC;KACvE;IAED,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxD,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,CACzB,UAAC,CAAC;YACA,OAAA,uBAAuB,CACrB;gBACE,GAAG,EAAE,UAAU,CAAC,GAAG;aACpB,EACD,OAAO,CACR,KAAK,KAAK;QALX,CAKW,CACd,CAAC;KACH;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,UAAU,CAAC,KAAK,CAAC,UAAC,CAAC,IAAK,OAAA,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,EAAnC,CAAmC,CAAC,CAAC;KACrE;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/feature.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Allocation,
|
|
1
|
+
import { Allocation, Context, Traffic, Feature, Force } from "@featurevisor/types";
|
|
2
2
|
import { DatafileReader } from "./datafileReader";
|
|
3
3
|
import { Logger } from "./logger";
|
|
4
4
|
export declare function getMatchedAllocation(traffic: Traffic, bucketValue: number): Allocation | undefined;
|
|
5
|
+
export declare function getMatchedTraffic(traffic: Traffic[], context: Context, datafileReader: DatafileReader): Traffic | undefined;
|
|
5
6
|
export interface MatchedTrafficAndAllocation {
|
|
6
7
|
matchedTraffic: Traffic | undefined;
|
|
7
8
|
matchedAllocation: Allocation | undefined;
|
|
8
9
|
}
|
|
9
|
-
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[],
|
|
10
|
-
export declare function findForceFromFeature(feature: Feature,
|
|
10
|
+
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[], context: Context, bucketValue: number, datafileReader: DatafileReader, logger: Logger): MatchedTrafficAndAllocation;
|
|
11
|
+
export declare function findForceFromFeature(feature: Feature, context: Context, datafileReader: DatafileReader): Force | undefined;
|
package/lib/feature.js
CHANGED
|
@@ -10,10 +10,18 @@ export function getMatchedAllocation(traffic, bucketValue) {
|
|
|
10
10
|
}
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function getMatchedTraffic(traffic, context, datafileReader) {
|
|
14
|
+
return traffic.find(function (t) {
|
|
15
|
+
if (!allGroupSegmentsAreMatched(typeof t.segments === "string" && t.segments !== "*" ? JSON.parse(t.segments) : t.segments, context, datafileReader)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function getMatchedTrafficAndAllocation(traffic, context, bucketValue, datafileReader, logger) {
|
|
14
22
|
var matchedAllocation;
|
|
15
23
|
var matchedTraffic = traffic.find(function (t) {
|
|
16
|
-
if (!allGroupSegmentsAreMatched(typeof t.segments === "string" && t.segments !== "*" ? JSON.parse(t.segments) : t.segments,
|
|
24
|
+
if (!allGroupSegmentsAreMatched(typeof t.segments === "string" && t.segments !== "*" ? JSON.parse(t.segments) : t.segments, context, datafileReader)) {
|
|
17
25
|
return false;
|
|
18
26
|
}
|
|
19
27
|
matchedAllocation = getMatchedAllocation(t, bucketValue);
|
|
@@ -27,16 +35,16 @@ export function getMatchedTrafficAndAllocation(traffic, attributes, bucketValue,
|
|
|
27
35
|
matchedAllocation: matchedAllocation,
|
|
28
36
|
};
|
|
29
37
|
}
|
|
30
|
-
export function findForceFromFeature(feature,
|
|
38
|
+
export function findForceFromFeature(feature, context, datafileReader) {
|
|
31
39
|
if (!feature.force) {
|
|
32
40
|
return undefined;
|
|
33
41
|
}
|
|
34
42
|
return feature.force.find(function (f) {
|
|
35
43
|
if (f.conditions) {
|
|
36
|
-
return allConditionsAreMatched(f.conditions,
|
|
44
|
+
return allConditionsAreMatched(f.conditions, context);
|
|
37
45
|
}
|
|
38
46
|
if (f.segments) {
|
|
39
|
-
return allGroupSegmentsAreMatched(f.segments,
|
|
47
|
+
return allGroupSegmentsAreMatched(f.segments, context, datafileReader);
|
|
40
48
|
}
|
|
41
49
|
return false;
|
|
42
50
|
});
|
package/lib/feature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,MAAM,UAAU,oBAAoB,CAClC,OAAgB,EAChB,WAAmB;IAEnB,KAAyB,UAAkB,EAAlB,KAAA,OAAO,CAAC,UAAU,EAAlB,cAAkB,EAAlB,IAAkB,EAAE;QAAxC,IAAM,UAAU,SAAA;QACb,IAAA,KAAe,UAAU,CAAC,KAAK,EAA9B,KAAK,QAAA,EAAE,GAAG,QAAoB,CAAC;QAEtC,IAAI,UAAU,CAAC,KAAK,IAAI,KAAK,IAAI,WAAW,IAAI,GAAG,IAAI,WAAW,EAAE;YAClE,OAAO,UAAU,CAAC;SACnB;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAOD,MAAM,UAAU,8BAA8B,CAC5C,OAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,MAAM,UAAU,oBAAoB,CAClC,OAAgB,EAChB,WAAmB;IAEnB,KAAyB,UAAkB,EAAlB,KAAA,OAAO,CAAC,UAAU,EAAlB,cAAkB,EAAlB,IAAkB,EAAE;QAAxC,IAAM,UAAU,SAAA;QACb,IAAA,KAAe,UAAU,CA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ED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,cAAc,gBAAA;QACd,iBAAiB,mBAAA;KAClB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAgB,EAChB,OAAgB,EAChB,cAA8B;IAE9B,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;QAClB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAC,CAAQ;QACjC,IAAI,CAAC,CAAC,UAAU,EAAE;YAChB,OAAO,uBAAuB,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SACvD;QAED,IAAI,CAAC,CAAC,QAAQ,EAAE;YACd,OAAO,0BAA0B,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;SACxE;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/lib/instance.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context, BucketKey, BucketValue, DatafileContent, Feature, FeatureKey, InitialFeatures, OverrideFeature, StickyFeatures, Traffic, VariableType, VariableValue, VariationValue, Variation, RuleKey, VariableKey, VariableSchema } from "@featurevisor/types";
|
|
2
2
|
import { Logger } from "./logger";
|
|
3
3
|
import { Emitter } from "./emitter";
|
|
4
4
|
export type ReadyCallback = () => void;
|
|
5
|
-
export type ActivationCallback = (featureName: string, variation: VariationValue,
|
|
6
|
-
export type ConfigureBucketKey = (feature: any,
|
|
7
|
-
export type ConfigureBucketValue = (feature: any,
|
|
5
|
+
export type ActivationCallback = (featureName: string, variation: VariationValue, context: Context, captureContext: Context) => void;
|
|
6
|
+
export type ConfigureBucketKey = (feature: any, context: any, bucketKey: BucketKey) => BucketKey;
|
|
7
|
+
export type ConfigureBucketValue = (feature: any, context: any, bucketValue: BucketValue) => BucketValue;
|
|
8
8
|
export interface Statuses {
|
|
9
9
|
ready: boolean;
|
|
10
10
|
refreshInProgress: boolean;
|
|
11
11
|
}
|
|
12
|
+
export type InterceptContext = (context: Context) => Context;
|
|
12
13
|
export interface InstanceOptions {
|
|
13
14
|
bucketKeySeparator?: string;
|
|
14
15
|
configureBucketKey?: ConfigureBucketKey;
|
|
@@ -17,7 +18,7 @@ export interface InstanceOptions {
|
|
|
17
18
|
datafileUrl?: string;
|
|
18
19
|
handleDatafileFetch?: (datafileUrl: string) => Promise<DatafileContent>;
|
|
19
20
|
initialFeatures?: InitialFeatures;
|
|
20
|
-
|
|
21
|
+
interceptContext?: InterceptContext;
|
|
21
22
|
logger?: Logger;
|
|
22
23
|
onActivation?: ActivationCallback;
|
|
23
24
|
onReady?: ReadyCallback;
|
|
@@ -29,6 +30,9 @@ export interface InstanceOptions {
|
|
|
29
30
|
export type DatafileFetchHandler = (datafileUrl: string) => Promise<DatafileContent>;
|
|
30
31
|
export declare enum EvaluationReason {
|
|
31
32
|
NOT_FOUND = "not_found",
|
|
33
|
+
NO_VARIATIONS = "no_variations",
|
|
34
|
+
DISABLED = "disabled",
|
|
35
|
+
OUT_OF_RANGE = "out_of_range",
|
|
32
36
|
FORCED = "forced",
|
|
33
37
|
INITIAL = "initial",
|
|
34
38
|
STICKY = "sticky",
|
|
@@ -44,13 +48,17 @@ export interface Evaluation {
|
|
|
44
48
|
bucketValue?: BucketValue;
|
|
45
49
|
ruleKey?: RuleKey;
|
|
46
50
|
error?: Error;
|
|
51
|
+
enabled?: boolean;
|
|
52
|
+
traffic?: Traffic;
|
|
53
|
+
sticky?: OverrideFeature;
|
|
54
|
+
initial?: OverrideFeature;
|
|
47
55
|
variation?: Variation;
|
|
48
56
|
variationValue?: VariationValue;
|
|
49
57
|
variableKey?: VariableKey;
|
|
50
58
|
variableValue?: VariableValue;
|
|
51
59
|
variableSchema?: VariableSchema;
|
|
52
60
|
}
|
|
53
|
-
type FieldType =
|
|
61
|
+
type FieldType = string | VariableType;
|
|
54
62
|
type ValueType = VariableValue;
|
|
55
63
|
export declare function getValueByType(value: ValueType, fieldType: FieldType): ValueType;
|
|
56
64
|
export declare class FeaturevisorInstance {
|
|
@@ -60,7 +68,7 @@ export declare class FeaturevisorInstance {
|
|
|
60
68
|
private datafileUrl?;
|
|
61
69
|
private handleDatafileFetch?;
|
|
62
70
|
private initialFeatures?;
|
|
63
|
-
private
|
|
71
|
+
private interceptContext?;
|
|
64
72
|
private logger;
|
|
65
73
|
private refreshInterval?;
|
|
66
74
|
private stickyFeatures?;
|
|
@@ -93,35 +101,36 @@ export declare class FeaturevisorInstance {
|
|
|
93
101
|
refresh(): void;
|
|
94
102
|
startRefreshing(): void;
|
|
95
103
|
stopRefreshing(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Flag
|
|
106
|
+
*/
|
|
107
|
+
evaluateFlag(featureKey: FeatureKey | Feature, context?: Context): Evaluation;
|
|
108
|
+
isEnabled(featureKey: FeatureKey | Feature, context?: Context): boolean;
|
|
96
109
|
/**
|
|
97
110
|
* Variation
|
|
98
111
|
*/
|
|
99
|
-
evaluateVariation(featureKey: FeatureKey | Feature,
|
|
100
|
-
getVariation(featureKey: FeatureKey | Feature,
|
|
101
|
-
getVariationBoolean(featureKey: FeatureKey | Feature, attributes?: Attributes): boolean | undefined;
|
|
102
|
-
getVariationString(featureKey: FeatureKey | Feature, attributes?: Attributes): string | undefined;
|
|
103
|
-
getVariationInteger(featureKey: FeatureKey | Feature, attributes?: Attributes): number | undefined;
|
|
104
|
-
getVariationDouble(featureKey: FeatureKey | Feature, attributes?: Attributes): number | undefined;
|
|
112
|
+
evaluateVariation(featureKey: FeatureKey | Feature, context?: Context): Evaluation;
|
|
113
|
+
getVariation(featureKey: FeatureKey | Feature, context?: Context): VariationValue | undefined;
|
|
105
114
|
/**
|
|
106
115
|
* Activate
|
|
107
116
|
*/
|
|
108
|
-
activate(featureKey: FeatureKey,
|
|
109
|
-
activateBoolean(featureKey: FeatureKey,
|
|
110
|
-
activateString(featureKey: FeatureKey,
|
|
111
|
-
activateInteger(featureKey: FeatureKey,
|
|
112
|
-
activateDouble(featureKey: FeatureKey,
|
|
117
|
+
activate(featureKey: FeatureKey, context?: Context): VariationValue | undefined;
|
|
118
|
+
activateBoolean(featureKey: FeatureKey, context?: Context): boolean | undefined;
|
|
119
|
+
activateString(featureKey: FeatureKey, context?: Context): string | undefined;
|
|
120
|
+
activateInteger(featureKey: FeatureKey, context?: Context): number | undefined;
|
|
121
|
+
activateDouble(featureKey: FeatureKey, context?: Context): number | undefined;
|
|
113
122
|
/**
|
|
114
123
|
* Variable
|
|
115
124
|
*/
|
|
116
|
-
evaluateVariable(featureKey: FeatureKey | Feature, variableKey: VariableKey,
|
|
117
|
-
getVariable(featureKey: FeatureKey | Feature, variableKey: string,
|
|
118
|
-
getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string,
|
|
119
|
-
getVariableString(featureKey: FeatureKey | Feature, variableKey: string,
|
|
120
|
-
getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string,
|
|
121
|
-
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string,
|
|
122
|
-
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string,
|
|
123
|
-
getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string,
|
|
124
|
-
getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string,
|
|
125
|
+
evaluateVariable(featureKey: FeatureKey | Feature, variableKey: VariableKey, context?: Context): Evaluation;
|
|
126
|
+
getVariable(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): VariableValue | undefined;
|
|
127
|
+
getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): boolean | undefined;
|
|
128
|
+
getVariableString(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string | undefined;
|
|
129
|
+
getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
|
|
130
|
+
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
|
|
131
|
+
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string[] | undefined;
|
|
132
|
+
getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
|
|
133
|
+
getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
|
|
125
134
|
}
|
|
126
135
|
export declare function createInstance(options: InstanceOptions): FeaturevisorInstance;
|
|
127
136
|
export {};
|