@featurevisor/sdk 0.36.0 → 0.37.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 +11 -0
- package/README.md +14 -14
- package/coverage/clover.xml +224 -224
- package/coverage/coverage-final.json +4 -4
- package/coverage/lcov-report/bucket.ts.html +1 -1
- package/coverage/lcov-report/conditions.ts.html +38 -38
- package/coverage/lcov-report/datafileReader.ts.html +1 -1
- package/coverage/lcov-report/emitter.ts.html +1 -1
- package/coverage/lcov-report/feature.ts.html +7 -7
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/instance.ts.html +74 -113
- package/coverage/lcov-report/logger.ts.html +1 -1
- package/coverage/lcov-report/segments.ts.html +10 -10
- package/coverage/lcov.info +391 -391
- 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 +3 -3
- package/lib/feature.js +5 -5
- package/lib/feature.js.map +1 -1
- package/lib/instance.d.ts +27 -26
- package/lib/instance.js +80 -86
- 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 +6 -6
- package/src/instance.spec.ts +6 -6
- package/src/instance.ts +70 -83
- package/src/segments.ts +9 -9
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,kBAAkB,CAAC;AAInD,MAAM,UAAU,kBAAkB,CAAC,SAAyB,EAAE,
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,UAAU,kBAAkB,CAAC,SAAyB,EAAE,OAAgB;IACpE,IAAA,SAAS,GAAsB,SAAS,UAA/B,EAAE,QAAQ,GAAY,SAAS,SAArB,EAAE,KA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ACA,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,4 +1,4 @@
|
|
|
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;
|
|
@@ -6,5 +6,5 @@ export interface MatchedTrafficAndAllocation {
|
|
|
6
6
|
matchedTraffic: Traffic | undefined;
|
|
7
7
|
matchedAllocation: Allocation | undefined;
|
|
8
8
|
}
|
|
9
|
-
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[],
|
|
10
|
-
export declare function findForceFromFeature(feature: Feature,
|
|
9
|
+
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[], context: Context, bucketValue: number, datafileReader: DatafileReader, logger: Logger): MatchedTrafficAndAllocation;
|
|
10
|
+
export declare function findForceFromFeature(feature: Feature, context: Context, datafileReader: DatafileReader): Force | undefined;
|
package/lib/feature.js
CHANGED
|
@@ -10,10 +10,10 @@ export function getMatchedAllocation(traffic, bucketValue) {
|
|
|
10
10
|
}
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
export function getMatchedTrafficAndAllocation(traffic,
|
|
13
|
+
export function getMatchedTrafficAndAllocation(traffic, context, bucketValue, datafileReader, logger) {
|
|
14
14
|
var matchedAllocation;
|
|
15
15
|
var matchedTraffic = traffic.find(function (t) {
|
|
16
|
-
if (!allGroupSegmentsAreMatched(typeof t.segments === "string" && t.segments !== "*" ? JSON.parse(t.segments) : t.segments,
|
|
16
|
+
if (!allGroupSegmentsAreMatched(typeof t.segments === "string" && t.segments !== "*" ? JSON.parse(t.segments) : t.segments, context, datafileReader)) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
matchedAllocation = getMatchedAllocation(t, bucketValue);
|
|
@@ -27,16 +27,16 @@ export function getMatchedTrafficAndAllocation(traffic, attributes, bucketValue,
|
|
|
27
27
|
matchedAllocation: matchedAllocation,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
export function findForceFromFeature(feature,
|
|
30
|
+
export function findForceFromFeature(feature, context, datafileReader) {
|
|
31
31
|
if (!feature.force) {
|
|
32
32
|
return undefined;
|
|
33
33
|
}
|
|
34
34
|
return feature.force.find(function (f) {
|
|
35
35
|
if (f.conditions) {
|
|
36
|
-
return allConditionsAreMatched(f.conditions,
|
|
36
|
+
return allConditionsAreMatched(f.conditions, context);
|
|
37
37
|
}
|
|
38
38
|
if (f.segments) {
|
|
39
|
-
return allGroupSegmentsAreMatched(f.segments,
|
|
39
|
+
return allGroupSegmentsAreMatched(f.segments, context, datafileReader);
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
42
|
});
|
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,IA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AC,QAAQ,EAC1F,OAAO,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 {
|
|
1
|
+
import { Context, BucketKey, BucketValue, DatafileContent, Feature, FeatureKey, InitialFeatures, StickyFeatures, VariableType, VariableValue, VariationType, 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;
|
|
@@ -60,7 +61,7 @@ export declare class FeaturevisorInstance {
|
|
|
60
61
|
private datafileUrl?;
|
|
61
62
|
private handleDatafileFetch?;
|
|
62
63
|
private initialFeatures?;
|
|
63
|
-
private
|
|
64
|
+
private interceptContext?;
|
|
64
65
|
private logger;
|
|
65
66
|
private refreshInterval?;
|
|
66
67
|
private stickyFeatures?;
|
|
@@ -96,32 +97,32 @@ export declare class FeaturevisorInstance {
|
|
|
96
97
|
/**
|
|
97
98
|
* Variation
|
|
98
99
|
*/
|
|
99
|
-
evaluateVariation(featureKey: FeatureKey | Feature,
|
|
100
|
-
getVariation(featureKey: FeatureKey | Feature,
|
|
101
|
-
getVariationBoolean(featureKey: FeatureKey | Feature,
|
|
102
|
-
getVariationString(featureKey: FeatureKey | Feature,
|
|
103
|
-
getVariationInteger(featureKey: FeatureKey | Feature,
|
|
104
|
-
getVariationDouble(featureKey: FeatureKey | Feature,
|
|
100
|
+
evaluateVariation(featureKey: FeatureKey | Feature, context?: Context): Evaluation;
|
|
101
|
+
getVariation(featureKey: FeatureKey | Feature, context?: Context): VariationValue | undefined;
|
|
102
|
+
getVariationBoolean(featureKey: FeatureKey | Feature, context?: Context): boolean | undefined;
|
|
103
|
+
getVariationString(featureKey: FeatureKey | Feature, context?: Context): string | undefined;
|
|
104
|
+
getVariationInteger(featureKey: FeatureKey | Feature, context?: Context): number | undefined;
|
|
105
|
+
getVariationDouble(featureKey: FeatureKey | Feature, context?: Context): number | undefined;
|
|
105
106
|
/**
|
|
106
107
|
* Activate
|
|
107
108
|
*/
|
|
108
|
-
activate(featureKey: FeatureKey,
|
|
109
|
-
activateBoolean(featureKey: FeatureKey,
|
|
110
|
-
activateString(featureKey: FeatureKey,
|
|
111
|
-
activateInteger(featureKey: FeatureKey,
|
|
112
|
-
activateDouble(featureKey: FeatureKey,
|
|
109
|
+
activate(featureKey: FeatureKey, context?: Context): VariationValue | undefined;
|
|
110
|
+
activateBoolean(featureKey: FeatureKey, context?: Context): boolean | undefined;
|
|
111
|
+
activateString(featureKey: FeatureKey, context?: Context): string | undefined;
|
|
112
|
+
activateInteger(featureKey: FeatureKey, context?: Context): number | undefined;
|
|
113
|
+
activateDouble(featureKey: FeatureKey, context?: Context): number | undefined;
|
|
113
114
|
/**
|
|
114
115
|
* Variable
|
|
115
116
|
*/
|
|
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,
|
|
117
|
+
evaluateVariable(featureKey: FeatureKey | Feature, variableKey: VariableKey, context?: Context): Evaluation;
|
|
118
|
+
getVariable(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): VariableValue | undefined;
|
|
119
|
+
getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): boolean | undefined;
|
|
120
|
+
getVariableString(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string | undefined;
|
|
121
|
+
getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
|
|
122
|
+
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
|
|
123
|
+
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string[] | undefined;
|
|
124
|
+
getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
|
|
125
|
+
getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
|
|
125
126
|
}
|
|
126
127
|
export declare function createInstance(options: InstanceOptions): FeaturevisorInstance;
|
|
127
128
|
export {};
|