@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.
@@ -1,3 +1,3 @@
1
- import { Attributes, Condition, PlainCondition } from "@featurevisor/types";
2
- export declare function conditionIsMatched(condition: PlainCondition, attributes: Attributes): boolean;
3
- export declare function allConditionsAreMatched(conditions: Condition[] | Condition, attributes: Attributes): boolean;
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, attributes) {
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 attributes[attribute] === value;
5
+ return context[attribute] === value;
6
6
  }
7
7
  else if (operator === "notEquals") {
8
- return attributes[attribute] !== value;
8
+ return context[attribute] !== value;
9
9
  }
10
10
  else if (operator === "before" || operator === "after") {
11
11
  // date comparisons
12
- var valueInAttributes = attributes[attribute];
13
- var dateInAttributes = valueInAttributes instanceof Date ? valueInAttributes : new Date(valueInAttributes);
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
- ? dateInAttributes < dateInCondition
17
- : dateInAttributes > dateInCondition;
16
+ ? dateInContext < dateInCondition
17
+ : dateInContext > dateInCondition;
18
18
  }
19
- else if (typeof attributes[attribute] === "string" && Array.isArray(value)) {
19
+ else if (typeof context[attribute] === "string" && Array.isArray(value)) {
20
20
  // array
21
- var valueInAttributes = attributes[attribute];
21
+ var valueInContext = context[attribute];
22
22
  if (operator === "in") {
23
- return value.indexOf(valueInAttributes) !== -1;
23
+ return value.indexOf(valueInContext) !== -1;
24
24
  }
25
25
  else if (operator === "notIn") {
26
- return value.indexOf(valueInAttributes) === -1;
26
+ return value.indexOf(valueInContext) === -1;
27
27
  }
28
28
  }
29
- else if (typeof attributes[attribute] === "string" && typeof value === "string") {
29
+ else if (typeof context[attribute] === "string" && typeof value === "string") {
30
30
  // string
31
- var valueInAttributes = attributes[attribute];
31
+ var valueInContext = context[attribute];
32
32
  if (operator === "contains") {
33
- return valueInAttributes.indexOf(value) !== -1;
33
+ return valueInContext.indexOf(value) !== -1;
34
34
  }
35
35
  else if (operator === "notContains") {
36
- return valueInAttributes.indexOf(value) === -1;
36
+ return valueInContext.indexOf(value) === -1;
37
37
  }
38
38
  else if (operator === "startsWith") {
39
- return valueInAttributes.startsWith(value);
39
+ return valueInContext.startsWith(value);
40
40
  }
41
41
  else if (operator === "endsWith") {
42
- return valueInAttributes.endsWith(value);
42
+ return valueInContext.endsWith(value);
43
43
  }
44
44
  else if (operator === "semverEquals") {
45
- return compareVersions(valueInAttributes, value) === 0;
45
+ return compareVersions(valueInContext, value) === 0;
46
46
  }
47
47
  else if (operator === "semverNotEquals") {
48
- return compareVersions(valueInAttributes, value) !== 0;
48
+ return compareVersions(valueInContext, value) !== 0;
49
49
  }
50
50
  else if (operator === "semverGreaterThan") {
51
- return compareVersions(valueInAttributes, value) === 1;
51
+ return compareVersions(valueInContext, value) === 1;
52
52
  }
53
53
  else if (operator === "semverGreaterThanOrEquals") {
54
- return compareVersions(valueInAttributes, value) >= 0;
54
+ return compareVersions(valueInContext, value) >= 0;
55
55
  }
56
56
  else if (operator === "semverLessThan") {
57
- return compareVersions(valueInAttributes, value) === -1;
57
+ return compareVersions(valueInContext, value) === -1;
58
58
  }
59
59
  else if (operator === "semverLessThanOrEquals") {
60
- return compareVersions(valueInAttributes, value) <= 0;
60
+ return compareVersions(valueInContext, value) <= 0;
61
61
  }
62
62
  }
63
- else if (typeof attributes[attribute] === "number" && typeof value === "number") {
63
+ else if (typeof context[attribute] === "number" && typeof value === "number") {
64
64
  // numeric
65
- var valueInAttributes = attributes[attribute];
65
+ var valueInContext = context[attribute];
66
66
  if (operator === "greaterThan") {
67
- return valueInAttributes > value;
67
+ return valueInContext > value;
68
68
  }
69
69
  else if (operator === "greaterThanOrEquals") {
70
- return valueInAttributes >= value;
70
+ return valueInContext >= value;
71
71
  }
72
72
  else if (operator === "lessThan") {
73
- return valueInAttributes < value;
73
+ return valueInContext < value;
74
74
  }
75
75
  else if (operator === "lessThanOrEquals") {
76
- return valueInAttributes <= value;
76
+ return valueInContext <= value;
77
77
  }
78
78
  }
79
79
  return false;
80
80
  }
81
- export function allConditionsAreMatched(conditions, attributes) {
81
+ export function allConditionsAreMatched(conditions, context) {
82
82
  if ("attribute" in conditions) {
83
- return conditionIsMatched(conditions, attributes);
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, attributes); });
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, attributes); });
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
- }, attributes) === false;
95
+ }, context) === false;
96
96
  });
97
97
  }
98
98
  if (Array.isArray(conditions)) {
99
- return conditions.every(function (c) { return allConditionsAreMatched(c, attributes); });
99
+ return conditions.every(function (c) { return allConditionsAreMatched(c, context); });
100
100
  }
101
101
  return false;
102
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;A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AACf,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,UAAmC,EACnC,OAAgB;IAEhB,IAAI,WAAW,IAAI,UAAU,EAAE;QAC7B,OAAO,kBAAkB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;KAChD;IAED,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxD,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,UAAC,CAAC,IAAK,OAAA,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,EAAnC,CAAmC,CAAC,CAAC;KACzE;IAED,IAAI,IAAI,IAAI,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,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, Attributes, Traffic, Feature, Force } from "@featurevisor/types";
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[], attributes: Attributes, bucketValue: number, datafileReader: DatafileReader, logger: Logger): MatchedTrafficAndAllocation;
10
- export declare function findForceFromFeature(feature: Feature, attributes: Attributes, datafileReader: DatafileReader): Force | undefined;
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 getMatchedTrafficAndAllocation(traffic, attributes, bucketValue, datafileReader, logger) {
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, attributes, datafileReader)) {
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, attributes, datafileReader) {
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, attributes);
44
+ return allConditionsAreMatched(f.conditions, context);
37
45
  }
38
46
  if (f.segments) {
39
- return allGroupSegmentsAreMatched(f.segments, attributes, datafileReader);
47
+ return allGroupSegmentsAreMatched(f.segments, context, datafileReader);
40
48
  }
41
49
  return false;
42
50
  });
@@ -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,UAAsB,EACtB,WAAmB,EACnB,cAA8B,EAC9B,MAAc;IAEd,IAAI,iBAAyC,CAAC;IAE9C,IAAM,cAAc,GA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,EACP,cAAc,CACf,EACD;YACA,OAAO,KAAK,CAAC;SACd;QAED,iBAAiB,GAAG,oBAAoB,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QAEzD,IAAI,iBAAiB,EAAE;YACrB,OAAO,IAAI,CAAC;SACb;QAED,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 { Attributes, BucketKey, BucketValue, DatafileContent, Feature, FeatureKey, InitialFeatures, StickyFeatures, VariableType, VariableValue, VariationType, VariationValue, Variation, RuleKey, VariableKey, VariableSchema } from "@featurevisor/types";
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, attributes: Attributes, captureAttributes: Attributes) => void;
6
- export type ConfigureBucketKey = (feature: any, attributes: any, bucketKey: BucketKey) => BucketKey;
7
- export type ConfigureBucketValue = (feature: any, attributes: any, bucketValue: BucketValue) => BucketValue;
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
- interceptAttributes?: (attributes: Attributes) => Attributes;
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 = VariationType | VariableType;
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 interceptAttributes?;
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, attributes?: Attributes): Evaluation;
100
- getVariation(featureKey: FeatureKey | Feature, attributes?: Attributes): VariationValue | undefined;
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, attributes?: Attributes): VariationValue | undefined;
109
- activateBoolean(featureKey: FeatureKey, attributes?: Attributes): boolean | undefined;
110
- activateString(featureKey: FeatureKey, attributes?: Attributes): string | undefined;
111
- activateInteger(featureKey: FeatureKey, attributes?: Attributes): number | undefined;
112
- activateDouble(featureKey: FeatureKey, attributes?: Attributes): number | undefined;
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, attributes?: Attributes): Evaluation;
117
- getVariable(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): VariableValue | undefined;
118
- getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): boolean | undefined;
119
- getVariableString(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): string | undefined;
120
- getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): number | undefined;
121
- getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): number | undefined;
122
- getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): string[] | undefined;
123
- getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): T | undefined;
124
- getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): T | undefined;
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 {};