flagsmith-nodejs 2.3.0 → 2.4.1
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/.vscode/launch.json +18 -0
- package/build/flagsmith-engine/segments/constants.d.ts +6 -0
- package/build/flagsmith-engine/segments/constants.js +8 -2
- package/build/flagsmith-engine/segments/evaluators.d.ts +2 -1
- package/build/flagsmith-engine/segments/evaluators.js +9 -2
- package/build/flagsmith-engine/segments/models.d.ts +3 -3
- package/build/flagsmith-engine/segments/models.js +26 -1
- package/build/sdk/index.js +2 -1
- package/examples/caching/package-lock.json +2488 -6600
- package/examples/caching/package.json +1 -1
- package/examples/custom-fetch-agent/package-lock.json +2583 -6609
- package/examples/custom-fetch-agent/package.json +1 -1
- package/examples/local-evaluation/package-lock.json +2493 -6601
- package/examples/local-evaluation/package.json +1 -1
- package/flagsmith-engine/segments/constants.ts +7 -1
- package/flagsmith-engine/segments/evaluators.ts +10 -6
- package/flagsmith-engine/segments/models.ts +15 -5
- package/package.json +1 -1
- package/sdk/index.ts +2 -1
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +12591 -0
- package/tests/engine/engine-tests/engine-test-data/readme.md +30 -0
- package/tests/engine/unit/segments/segment_evaluators.test.ts +27 -0
- package/tests/engine/unit/segments/segments_model.test.ts +8 -1
- package/tests/sdk/data/environment.json +23 -1
- package/tests/sdk/flagsmith-identity-flags.test.ts +18 -1
- package/tests/sdk/flagsmith.test.ts +25 -9
- package/.idea/flagsmith-nodejs-client.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/examples/api-proxy/.idea/api-proxy.iml +0 -12
- package/examples/api-proxy/.idea/codeStyles/Project.xml +0 -60
- package/examples/api-proxy/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/examples/api-proxy/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/examples/api-proxy/.idea/modules.xml +0 -8
- package/examples/api-proxy/.idea/vcs.xml +0 -6
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"bugs": "https://github.com/vferdiansyah/nodejs-es6-boilerplate/issues",
|
|
40
40
|
"homepage": "https://github.com/vferdiansyah/nodejs-es6-boilerplate#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/cli": "^7.
|
|
42
|
+
"@babel/cli": "^7.18.10",
|
|
43
43
|
"@babel/core": "^7.5.5",
|
|
44
44
|
"@babel/preset-env": "^7.5.5",
|
|
45
45
|
"eslint": "^6.2.1",
|
|
@@ -16,6 +16,9 @@ export const NOT_CONTAINS = 'NOT_CONTAINS';
|
|
|
16
16
|
export const NOT_EQUAL = 'NOT_EQUAL';
|
|
17
17
|
export const REGEX = 'REGEX';
|
|
18
18
|
export const PERCENTAGE_SPLIT = 'PERCENTAGE_SPLIT';
|
|
19
|
+
export const IS_SET = 'IS_SET';
|
|
20
|
+
export const IS_NOT_SET = 'IS_NOT_SET';
|
|
21
|
+
export const MODULO = 'MODULO';
|
|
19
22
|
|
|
20
23
|
export const CONDITION_OPERATORS = {
|
|
21
24
|
EQUAL,
|
|
@@ -27,5 +30,8 @@ export const CONDITION_OPERATORS = {
|
|
|
27
30
|
NOT_CONTAINS,
|
|
28
31
|
NOT_EQUAL,
|
|
29
32
|
REGEX,
|
|
30
|
-
PERCENTAGE_SPLIT
|
|
33
|
+
PERCENTAGE_SPLIT,
|
|
34
|
+
IS_SET,
|
|
35
|
+
IS_NOT_SET,
|
|
36
|
+
MODULO
|
|
31
37
|
};
|
|
@@ -2,7 +2,7 @@ import { EnvironmentModel } from '../environments/models';
|
|
|
2
2
|
import { IdentityModel } from '../identities/models';
|
|
3
3
|
import { TraitModel } from '../identities/traits/models';
|
|
4
4
|
import { getHashedPercentateForObjIds } from '../utils/hashing';
|
|
5
|
-
import { PERCENTAGE_SPLIT } from './constants';
|
|
5
|
+
import { PERCENTAGE_SPLIT, IS_SET, IS_NOT_SET } from './constants';
|
|
6
6
|
import { SegmentConditionModel, SegmentModel, SegmentRuleModel } from './models';
|
|
7
7
|
|
|
8
8
|
export function getIdentitySegments(
|
|
@@ -55,18 +55,22 @@ function traitsMatchSegmentRule(
|
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function traitsMatchSegmentCondition(
|
|
58
|
+
export function traitsMatchSegmentCondition(
|
|
59
59
|
identityTraits: TraitModel[],
|
|
60
60
|
condition: SegmentConditionModel,
|
|
61
61
|
segmentId: number | string,
|
|
62
62
|
identityId: number | string
|
|
63
63
|
): boolean {
|
|
64
64
|
if (condition.operator == PERCENTAGE_SPLIT) {
|
|
65
|
-
return getHashedPercentateForObjIds([segmentId, identityId]) <= parseFloat(condition.value);
|
|
65
|
+
return getHashedPercentateForObjIds([segmentId, identityId]) <= parseFloat(String(condition.value));
|
|
66
66
|
}
|
|
67
|
-
|
|
68
67
|
const traits = identityTraits.filter(t => t.traitKey === condition.property_);
|
|
69
68
|
const trait = traits.length > 0 ? traits[0] : undefined;
|
|
70
|
-
|
|
69
|
+
if (condition.operator === IS_SET ) {
|
|
70
|
+
return !!trait;
|
|
71
|
+
} else if (condition.operator === IS_NOT_SET){
|
|
72
|
+
return trait == undefined;
|
|
73
|
+
}
|
|
71
74
|
return trait ? condition.matchesTraitValue(trait.traitValue) : false;
|
|
72
|
-
|
|
75
|
+
|
|
76
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
NONE_RULE,
|
|
9
9
|
NOT_CONTAINS,
|
|
10
10
|
REGEX,
|
|
11
|
+
MODULO,
|
|
11
12
|
CONDITION_OPERATORS
|
|
12
13
|
} from './constants';
|
|
13
14
|
import { isSemver } from './util';
|
|
@@ -44,14 +45,15 @@ export const getMatchingFunctions = (semver: boolean) => (semver ? semverMatchin
|
|
|
44
45
|
export class SegmentConditionModel {
|
|
45
46
|
EXCEPTION_OPERATOR_METHODS: { [key: string]: string } = {
|
|
46
47
|
[NOT_CONTAINS]: 'evaluateNotContains',
|
|
47
|
-
[REGEX]: 'evaluateRegex'
|
|
48
|
+
[REGEX]: 'evaluateRegex',
|
|
49
|
+
[MODULO]: 'evaluateModulo',
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
operator: string;
|
|
51
|
-
value: string;
|
|
52
|
-
property_: string | undefined;
|
|
53
|
+
value: string | null | undefined;
|
|
54
|
+
property_: string | null | undefined;
|
|
53
55
|
|
|
54
|
-
constructor(operator: string, value
|
|
56
|
+
constructor(operator: string, value?: string | null | undefined, property?: string | null | undefined) {
|
|
55
57
|
this.operator = operator;
|
|
56
58
|
this.value = value;
|
|
57
59
|
this.property_ = property;
|
|
@@ -63,7 +65,15 @@ export class SegmentConditionModel {
|
|
|
63
65
|
return !traitValue.includes(this.value);
|
|
64
66
|
},
|
|
65
67
|
evaluateRegex: (traitValue: any) => {
|
|
66
|
-
return !!traitValue.match(new RegExp(this.value));
|
|
68
|
+
return !!this.value && !!traitValue.match(new RegExp(this.value));
|
|
69
|
+
},
|
|
70
|
+
evaluateModulo: (traitValue: any) => {
|
|
71
|
+
if (isNaN(parseFloat(traitValue)) || !this.value) {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
const parts = (this.value).split("|");
|
|
75
|
+
const [divisor, reminder] = [parseFloat(parts[0]), parseFloat(parts[1])];
|
|
76
|
+
return traitValue % divisor === reminder
|
|
67
77
|
}
|
|
68
78
|
};
|
|
69
79
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flagsmith-nodejs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"repository": {
|
package/sdk/index.ts
CHANGED
|
@@ -323,7 +323,8 @@ export class Flagsmith {
|
|
|
323
323
|
const flags = Flags.fromFeatureStateModels({
|
|
324
324
|
featureStates: featureStates,
|
|
325
325
|
analyticsProcessor: this.analyticsProcessor,
|
|
326
|
-
defaultFlagHandler: this.defaultFlagHandler
|
|
326
|
+
defaultFlagHandler: this.defaultFlagHandler,
|
|
327
|
+
identityID: identityModel.djangoID || identityModel.identityUuid
|
|
327
328
|
});
|
|
328
329
|
|
|
329
330
|
if (!!this.cache) {
|