flagsmith-nodejs 2.0.0-beta.1 → 2.0.0-beta.4
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/.tool-versions +1 -0
- package/example/package-lock.json +1070 -2
- package/example/package.json +1 -0
- package/example/server/api/index.js +14 -7
- package/example/server/index.js +3 -0
- package/flagsmith-engine/environments/models.ts +8 -8
- package/flagsmith-engine/features/models.ts +7 -7
- package/flagsmith-engine/identities/models.ts +8 -8
- package/flagsmith-engine/identities/util.ts +1 -1
- package/flagsmith-engine/index.ts +20 -19
- package/flagsmith-engine/organisations/models.ts +6 -6
- package/flagsmith-engine/projects/models.ts +2 -3
- package/flagsmith-engine/segments/evaluators.ts +2 -2
- package/flagsmith-engine/utils/errors.ts +1 -0
- package/flagsmith-engine/utils/hashing/index.ts +9 -14
- package/index.ts +4 -1
- package/package.json +11 -8
- package/sdk/analytics.ts +0 -28
- package/sdk/index.ts +73 -26
- package/sdk/models.ts +3 -1
- package/sdk/polling_manager.ts +4 -4
- package/sdk/utils.ts +1 -1
- package/tests/sdk/data/environment.json +39 -2
- package/tests/sdk/flagsmith.test.ts +21 -2
- package/tests/sdk/polling.test.ts +1 -1
- package/tests/sdk/utils.ts +1 -1
- package/.idea/flagsmith-nodejs-client.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/build/flagsmith-engine/environments/integrations/models.d.ts +0 -4
- package/build/flagsmith-engine/environments/integrations/models.js +0 -8
- package/build/flagsmith-engine/environments/models.d.ts +0 -25
- package/build/flagsmith-engine/environments/models.js +0 -40
- package/build/flagsmith-engine/environments/util.d.ts +0 -3
- package/build/flagsmith-engine/environments/util.js +0 -19
- package/build/flagsmith-engine/features/constants.d.ts +0 -4
- package/build/flagsmith-engine/features/constants.js +0 -7
- package/build/flagsmith-engine/features/models.d.ts +0 -32
- package/build/flagsmith-engine/features/models.js +0 -85
- package/build/flagsmith-engine/features/util.d.ts +0 -3
- package/build/flagsmith-engine/features/util.js +0 -20
- package/build/flagsmith-engine/identities/models.d.ts +0 -15
- package/build/flagsmith-engine/identities/models.js +0 -47
- package/build/flagsmith-engine/identities/traits/models.d.ts +0 -5
- package/build/flagsmith-engine/identities/traits/models.js +0 -12
- package/build/flagsmith-engine/identities/util.d.ts +0 -4
- package/build/flagsmith-engine/identities/util.js +0 -22
- package/build/flagsmith-engine/index.d.ts +0 -8
- package/build/flagsmith-engine/index.js +0 -60
- package/build/flagsmith-engine/organisations/models.d.ts +0 -9
- package/build/flagsmith-engine/organisations/models.js +0 -21
- package/build/flagsmith-engine/organisations/util.d.ts +0 -2
- package/build/flagsmith-engine/organisations/util.js +0 -8
- package/build/flagsmith-engine/projects/models.d.ts +0 -10
- package/build/flagsmith-engine/projects/models.js +0 -18
- package/build/flagsmith-engine/projects/util.d.ts +0 -2
- package/build/flagsmith-engine/projects/util.js +0 -15
- package/build/flagsmith-engine/segments/constants.d.ts +0 -26
- package/build/flagsmith-engine/segments/constants.js +0 -31
- package/build/flagsmith-engine/segments/evaluators.d.ts +0 -6
- package/build/flagsmith-engine/segments/evaluators.js +0 -29
- package/build/flagsmith-engine/segments/models.d.ts +0 -31
- package/build/flagsmith-engine/segments/models.js +0 -83
- package/build/flagsmith-engine/segments/util.d.ts +0 -4
- package/build/flagsmith-engine/segments/util.js +0 -23
- package/build/flagsmith-engine/utils/collections.d.ts +0 -4
- package/build/flagsmith-engine/utils/collections.js +0 -16
- package/build/flagsmith-engine/utils/hashing/index.d.ts +0 -1
- package/build/flagsmith-engine/utils/hashing/index.js +0 -56
- package/build/flagsmith-engine/utils/index.d.ts +0 -1
- package/build/flagsmith-engine/utils/index.js +0 -14
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -7
- package/build/sdk/analytics.d.ts +0 -28
- package/build/sdk/analytics.js +0 -81
- package/build/sdk/errors.d.ts +0 -4
- package/build/sdk/errors.js +0 -9
- package/build/sdk/index.d.ts +0 -99
- package/build/sdk/index.js +0 -221
- package/build/sdk/models.d.ts +0 -55
- package/build/sdk/models.js +0 -102
- package/build/sdk/polling_manager.d.ts +0 -9
- package/build/sdk/polling_manager.js +0 -31
- package/build/sdk/utils.d.ts +0 -12
- package/build/sdk/utils.js +0 -45
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrganisationModel = void 0;
|
|
4
|
-
class OrganisationModel {
|
|
5
|
-
id;
|
|
6
|
-
name;
|
|
7
|
-
featureAnalytics;
|
|
8
|
-
stopServingFlags;
|
|
9
|
-
persistTraitData;
|
|
10
|
-
constructor(id, name, feature_analytics, stop_serving_flags, persist_trait_data) {
|
|
11
|
-
this.id = id;
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.featureAnalytics = feature_analytics;
|
|
14
|
-
this.stopServingFlags = stop_serving_flags;
|
|
15
|
-
this.persistTraitData = persist_trait_data;
|
|
16
|
-
}
|
|
17
|
-
get unique_slug() {
|
|
18
|
-
return this.id.toString() + '-' + this.name;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.OrganisationModel = OrganisationModel;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildOrganizationModel = void 0;
|
|
4
|
-
const models_1 = require("./models");
|
|
5
|
-
function buildOrganizationModel(organizationJSON) {
|
|
6
|
-
return new models_1.OrganisationModel(organizationJSON.id, organizationJSON.name, organizationJSON.feature_analytics, organizationJSON.stop_serving_flags, organizationJSON.persist_trait_data);
|
|
7
|
-
}
|
|
8
|
-
exports.buildOrganizationModel = buildOrganizationModel;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { OrganisationModel } from '../organisations/models';
|
|
2
|
-
import { SegmentModel } from '../segments/models';
|
|
3
|
-
export declare class ProjectModel {
|
|
4
|
-
id: number;
|
|
5
|
-
name: string;
|
|
6
|
-
organisation: OrganisationModel;
|
|
7
|
-
hideDisabledFlags: boolean;
|
|
8
|
-
segments: SegmentModel[];
|
|
9
|
-
constructor(id: number, name: string, hide_disabled_flags: boolean, organization: OrganisationModel);
|
|
10
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectModel = void 0;
|
|
4
|
-
class ProjectModel {
|
|
5
|
-
id;
|
|
6
|
-
name;
|
|
7
|
-
organisation;
|
|
8
|
-
hideDisabledFlags;
|
|
9
|
-
// FIXME
|
|
10
|
-
segments = [];
|
|
11
|
-
constructor(id, name, hide_disabled_flags, organization) {
|
|
12
|
-
this.id = id;
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.hideDisabledFlags = hide_disabled_flags;
|
|
15
|
-
this.organisation = organization;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ProjectModel = ProjectModel;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildProjectModel = void 0;
|
|
4
|
-
const util_1 = require("../organisations/util");
|
|
5
|
-
const util_2 = require("../segments/util");
|
|
6
|
-
const models_1 = require("./models");
|
|
7
|
-
function buildProjectModel(projectJSON) {
|
|
8
|
-
const segments = projectJSON['segments']
|
|
9
|
-
? projectJSON['segments'].map((s) => (0, util_2.buildSegmentModel)(s))
|
|
10
|
-
: [];
|
|
11
|
-
const model = new models_1.ProjectModel(projectJSON.id, projectJSON.name, projectJSON.hide_disabled_flags, (0, util_1.buildOrganizationModel)(projectJSON.organisation));
|
|
12
|
-
model.segments = segments;
|
|
13
|
-
return model;
|
|
14
|
-
}
|
|
15
|
-
exports.buildProjectModel = buildProjectModel;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const ALL_RULE = "ALL";
|
|
2
|
-
export declare const ANY_RULE = "ANY";
|
|
3
|
-
export declare const NONE_RULE = "NONE";
|
|
4
|
-
export declare const RULE_TYPES: string[];
|
|
5
|
-
export declare const EQUAL = "EQUAL";
|
|
6
|
-
export declare const GREATER_THAN = "GREATER_THAN";
|
|
7
|
-
export declare const LESS_THAN = "LESS_THAN";
|
|
8
|
-
export declare const LESS_THAN_INCLUSIVE = "LESS_THAN_INCLUSIVE";
|
|
9
|
-
export declare const CONTAINS = "CONTAINS";
|
|
10
|
-
export declare const GREATER_THAN_INCLUSIVE = "GREATER_THAN_INCLUSIVE";
|
|
11
|
-
export declare const NOT_CONTAINS = "NOT_CONTAINS";
|
|
12
|
-
export declare const NOT_EQUAL = "NOT_EQUAL";
|
|
13
|
-
export declare const REGEX = "REGEX";
|
|
14
|
-
export declare const PERCENTAGE_SPLIT = "PERCENTAGE_SPLIT";
|
|
15
|
-
export declare const CONDITION_OPERATORS: {
|
|
16
|
-
EQUAL: string;
|
|
17
|
-
GREATER_THAN: string;
|
|
18
|
-
LESS_THAN: string;
|
|
19
|
-
LESS_THAN_INCLUSIVE: string;
|
|
20
|
-
CONTAINS: string;
|
|
21
|
-
GREATER_THAN_INCLUSIVE: string;
|
|
22
|
-
NOT_CONTAINS: string;
|
|
23
|
-
NOT_EQUAL: string;
|
|
24
|
-
REGEX: string;
|
|
25
|
-
PERCENTAGE_SPLIT: string;
|
|
26
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONDITION_OPERATORS = exports.PERCENTAGE_SPLIT = exports.REGEX = exports.NOT_EQUAL = exports.NOT_CONTAINS = exports.GREATER_THAN_INCLUSIVE = exports.CONTAINS = exports.LESS_THAN_INCLUSIVE = exports.LESS_THAN = exports.GREATER_THAN = exports.EQUAL = exports.RULE_TYPES = exports.NONE_RULE = exports.ANY_RULE = exports.ALL_RULE = void 0;
|
|
4
|
-
// Segment Rules
|
|
5
|
-
exports.ALL_RULE = 'ALL';
|
|
6
|
-
exports.ANY_RULE = 'ANY';
|
|
7
|
-
exports.NONE_RULE = 'NONE';
|
|
8
|
-
exports.RULE_TYPES = [exports.ALL_RULE, exports.ANY_RULE, exports.NONE_RULE];
|
|
9
|
-
// Segment Condition Operators
|
|
10
|
-
exports.EQUAL = 'EQUAL';
|
|
11
|
-
exports.GREATER_THAN = 'GREATER_THAN';
|
|
12
|
-
exports.LESS_THAN = 'LESS_THAN';
|
|
13
|
-
exports.LESS_THAN_INCLUSIVE = 'LESS_THAN_INCLUSIVE';
|
|
14
|
-
exports.CONTAINS = 'CONTAINS';
|
|
15
|
-
exports.GREATER_THAN_INCLUSIVE = 'GREATER_THAN_INCLUSIVE';
|
|
16
|
-
exports.NOT_CONTAINS = 'NOT_CONTAINS';
|
|
17
|
-
exports.NOT_EQUAL = 'NOT_EQUAL';
|
|
18
|
-
exports.REGEX = 'REGEX';
|
|
19
|
-
exports.PERCENTAGE_SPLIT = 'PERCENTAGE_SPLIT';
|
|
20
|
-
exports.CONDITION_OPERATORS = {
|
|
21
|
-
EQUAL: exports.EQUAL,
|
|
22
|
-
GREATER_THAN: exports.GREATER_THAN,
|
|
23
|
-
LESS_THAN: exports.LESS_THAN,
|
|
24
|
-
LESS_THAN_INCLUSIVE: exports.LESS_THAN_INCLUSIVE,
|
|
25
|
-
CONTAINS: exports.CONTAINS,
|
|
26
|
-
GREATER_THAN_INCLUSIVE: exports.GREATER_THAN_INCLUSIVE,
|
|
27
|
-
NOT_CONTAINS: exports.NOT_CONTAINS,
|
|
28
|
-
NOT_EQUAL: exports.NOT_EQUAL,
|
|
29
|
-
REGEX: exports.REGEX,
|
|
30
|
-
PERCENTAGE_SPLIT: exports.PERCENTAGE_SPLIT
|
|
31
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EnvironmentModel } from '../environments/models';
|
|
2
|
-
import { IdentityModel } from '../identities/models';
|
|
3
|
-
import { TraitModel } from '../identities/traits/models';
|
|
4
|
-
import { SegmentModel } from './models';
|
|
5
|
-
export declare function getIdentitySegments(environment: EnvironmentModel, identity: IdentityModel, overrideTraits?: TraitModel[]): SegmentModel[];
|
|
6
|
-
export declare function evaluateIdentityInSegment(identity: IdentityModel, segment: SegmentModel, overrideTraits?: TraitModel[]): boolean;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateIdentityInSegment = exports.getIdentitySegments = void 0;
|
|
4
|
-
const hashing_1 = require("../utils/hashing");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
function getIdentitySegments(environment, identity, overrideTraits) {
|
|
7
|
-
return environment.project.segments.filter(segment => evaluateIdentityInSegment(identity, segment, overrideTraits));
|
|
8
|
-
}
|
|
9
|
-
exports.getIdentitySegments = getIdentitySegments;
|
|
10
|
-
function evaluateIdentityInSegment(identity, segment, overrideTraits) {
|
|
11
|
-
return (segment.rules.length > 0 &&
|
|
12
|
-
segment.rules.filter(rule => traitsMatchSegmentRule(overrideTraits || identity.identityTraits, rule, segment.id, identity.compositeKey)).length === segment.rules.length);
|
|
13
|
-
}
|
|
14
|
-
exports.evaluateIdentityInSegment = evaluateIdentityInSegment;
|
|
15
|
-
function traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId) {
|
|
16
|
-
const matchesConditions = rule.conditions.length > 0
|
|
17
|
-
? rule.matchingFunction()(rule.conditions.map(condition => traitsMatchSegmentCondition(identityTraits, condition, segmentId, identityId)))
|
|
18
|
-
: true;
|
|
19
|
-
return (matchesConditions &&
|
|
20
|
-
rule.rules.filter(rule => traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId)).length === rule.rules.length);
|
|
21
|
-
}
|
|
22
|
-
function traitsMatchSegmentCondition(identity_traits, condition, segmentId, identityId) {
|
|
23
|
-
if (condition.operator == constants_1.PERCENTAGE_SPLIT) {
|
|
24
|
-
return (0, hashing_1.getHashedPercentateForObjIds)([segmentId, identityId]) <= parseFloat(condition.value);
|
|
25
|
-
}
|
|
26
|
-
const traits = identity_traits.filter(t => t.traitKey === condition.property_);
|
|
27
|
-
const trait = traits.length > 0 ? traits[0] : undefined;
|
|
28
|
-
return trait ? condition.matchesTraitValue(trait.traitValue) : false;
|
|
29
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FeatureStateModel } from '../features/models';
|
|
2
|
-
export declare const all: (iterable: Array<any>) => boolean;
|
|
3
|
-
export declare const any: (iterable: Array<any>) => boolean;
|
|
4
|
-
export declare const matchingFunctions: {
|
|
5
|
-
[x: string]: (thisValue: any, otherValue: any) => any;
|
|
6
|
-
};
|
|
7
|
-
export declare class SegmentConditionModel {
|
|
8
|
-
EXCEPTION_OPERATOR_METHODS: {
|
|
9
|
-
[key: string]: string;
|
|
10
|
-
};
|
|
11
|
-
operator: string;
|
|
12
|
-
value: string;
|
|
13
|
-
property_: string | undefined;
|
|
14
|
-
constructor(operator: string, value: string, property?: string);
|
|
15
|
-
matchesTraitValue(traitValue: any): any;
|
|
16
|
-
}
|
|
17
|
-
export declare class SegmentRuleModel {
|
|
18
|
-
type: string;
|
|
19
|
-
rules: SegmentRuleModel[];
|
|
20
|
-
conditions: SegmentConditionModel[];
|
|
21
|
-
constructor(type: string);
|
|
22
|
-
static none(iterable: Array<any>): boolean;
|
|
23
|
-
matchingFunction(): CallableFunction;
|
|
24
|
-
}
|
|
25
|
-
export declare class SegmentModel {
|
|
26
|
-
id: number;
|
|
27
|
-
name: string;
|
|
28
|
-
rules: SegmentRuleModel[];
|
|
29
|
-
featureStates: FeatureStateModel[];
|
|
30
|
-
constructor(id: number, name: string);
|
|
31
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SegmentModel = exports.SegmentRuleModel = exports.SegmentConditionModel = exports.matchingFunctions = exports.any = exports.all = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
const all = (iterable) => iterable.filter(e => !!e).length === iterable.length;
|
|
7
|
-
exports.all = all;
|
|
8
|
-
const any = (iterable) => iterable.filter(e => !!e).length > 0;
|
|
9
|
-
exports.any = any;
|
|
10
|
-
exports.matchingFunctions = {
|
|
11
|
-
[constants_1.CONDITION_OPERATORS.EQUAL]: (thisValue, otherValue) => thisValue == otherValue,
|
|
12
|
-
[constants_1.CONDITION_OPERATORS.GREATER_THAN]: (thisValue, otherValue) => otherValue > thisValue,
|
|
13
|
-
[constants_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE]: (thisValue, otherValue) => otherValue >= thisValue,
|
|
14
|
-
[constants_1.CONDITION_OPERATORS.LESS_THAN]: (thisValue, otherValue) => thisValue > otherValue,
|
|
15
|
-
[constants_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE]: (thisValue, otherValue) => thisValue >= otherValue,
|
|
16
|
-
[constants_1.CONDITION_OPERATORS.NOT_EQUAL]: (thisValue, otherValue) => thisValue != otherValue,
|
|
17
|
-
[constants_1.CONDITION_OPERATORS.CONTAINS]: (thisValue, otherValue) => otherValue.includes(thisValue),
|
|
18
|
-
[constants_1.CONDITION_OPERATORS.NOT_CONTAINS]: (thisValue, otherValue) => !otherValue.includes(thisValue)
|
|
19
|
-
};
|
|
20
|
-
class SegmentConditionModel {
|
|
21
|
-
EXCEPTION_OPERATOR_METHODS = {
|
|
22
|
-
[constants_1.NOT_CONTAINS]: 'evaluateNotContains',
|
|
23
|
-
[constants_1.REGEX]: 'evaluateRegex'
|
|
24
|
-
};
|
|
25
|
-
operator;
|
|
26
|
-
value;
|
|
27
|
-
property_;
|
|
28
|
-
constructor(operator, value, property) {
|
|
29
|
-
this.operator = operator;
|
|
30
|
-
this.value = value;
|
|
31
|
-
this.property_ = property;
|
|
32
|
-
}
|
|
33
|
-
matchesTraitValue(traitValue) {
|
|
34
|
-
const evaluators = {
|
|
35
|
-
evaluateNotContains: (traitValue) => {
|
|
36
|
-
return !traitValue.includes(this.value);
|
|
37
|
-
},
|
|
38
|
-
evaluateRegex: (traitValue) => {
|
|
39
|
-
return !!traitValue.match(new RegExp(this.value));
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
// TODO: move this logic to the evaluator module
|
|
43
|
-
if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
|
|
44
|
-
const evaluatorFunction = evaluators[this.EXCEPTION_OPERATOR_METHODS[this.operator]];
|
|
45
|
-
return evaluatorFunction(traitValue);
|
|
46
|
-
}
|
|
47
|
-
const defaultFunction = (x, y) => false;
|
|
48
|
-
const matchingFunction = exports.matchingFunctions[this.operator] || defaultFunction;
|
|
49
|
-
const castToTypeOfTraitValue = (0, utils_1.getCastingFunction)(traitValue);
|
|
50
|
-
return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.SegmentConditionModel = SegmentConditionModel;
|
|
54
|
-
class SegmentRuleModel {
|
|
55
|
-
type;
|
|
56
|
-
rules = [];
|
|
57
|
-
conditions = [];
|
|
58
|
-
constructor(type) {
|
|
59
|
-
this.type = type;
|
|
60
|
-
}
|
|
61
|
-
static none(iterable) {
|
|
62
|
-
return iterable.filter(e => !!e).length === 0;
|
|
63
|
-
}
|
|
64
|
-
matchingFunction() {
|
|
65
|
-
return {
|
|
66
|
-
[constants_1.ANY_RULE]: exports.any,
|
|
67
|
-
[constants_1.ALL_RULE]: exports.all,
|
|
68
|
-
[constants_1.NONE_RULE]: SegmentRuleModel.none
|
|
69
|
-
}[this.type];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.SegmentRuleModel = SegmentRuleModel;
|
|
73
|
-
class SegmentModel {
|
|
74
|
-
id;
|
|
75
|
-
name;
|
|
76
|
-
rules = [];
|
|
77
|
-
featureStates = [];
|
|
78
|
-
constructor(id, name) {
|
|
79
|
-
this.id = id;
|
|
80
|
-
this.name = name;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.SegmentModel = SegmentModel;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { SegmentConditionModel, SegmentModel, SegmentRuleModel } from './models';
|
|
2
|
-
export declare function buildSegmentConditionModel(segmentConditionJSON: any): SegmentConditionModel;
|
|
3
|
-
export declare function buildSegmentRuleModel(ruleModelJSON: any): SegmentRuleModel;
|
|
4
|
-
export declare function buildSegmentModel(segmentModelJSON: any): SegmentModel;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSegmentModel = exports.buildSegmentRuleModel = exports.buildSegmentConditionModel = void 0;
|
|
4
|
-
const util_1 = require("../features/util");
|
|
5
|
-
const models_1 = require("./models");
|
|
6
|
-
function buildSegmentConditionModel(segmentConditionJSON) {
|
|
7
|
-
return new models_1.SegmentConditionModel(segmentConditionJSON.operator, segmentConditionJSON.value, segmentConditionJSON.property_);
|
|
8
|
-
}
|
|
9
|
-
exports.buildSegmentConditionModel = buildSegmentConditionModel;
|
|
10
|
-
function buildSegmentRuleModel(ruleModelJSON) {
|
|
11
|
-
const ruleModel = new models_1.SegmentRuleModel(ruleModelJSON.type);
|
|
12
|
-
ruleModel.rules = ruleModelJSON.rules.map((r) => buildSegmentRuleModel(r));
|
|
13
|
-
ruleModel.conditions = ruleModelJSON.conditions.map((c) => buildSegmentConditionModel(c));
|
|
14
|
-
return ruleModel;
|
|
15
|
-
}
|
|
16
|
-
exports.buildSegmentRuleModel = buildSegmentRuleModel;
|
|
17
|
-
function buildSegmentModel(segmentModelJSON) {
|
|
18
|
-
const model = new models_1.SegmentModel(segmentModelJSON.id, segmentModelJSON.name);
|
|
19
|
-
model.featureStates = segmentModelJSON['feature_states'].map((fs) => (0, util_1.buildFeatureStateModel)(fs));
|
|
20
|
-
model.rules = segmentModelJSON['rules'].map((r) => buildSegmentRuleModel(r));
|
|
21
|
-
return model;
|
|
22
|
-
}
|
|
23
|
-
exports.buildSegmentModel = buildSegmentModel;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IdentityFeaturesList = void 0;
|
|
4
|
-
class IdentityFeaturesList extends Array {
|
|
5
|
-
push(...e) {
|
|
6
|
-
for (const [_, item] of e.entries()) {
|
|
7
|
-
for (const [k, v] of this.entries()) {
|
|
8
|
-
if (v.djangoID === item.djangoID) {
|
|
9
|
-
throw new Error('feature state for this feature already exists');
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return super.push(...e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.IdentityFeaturesList = IdentityFeaturesList;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getHashedPercentateForObjIds(objectIds: Array<any>, iterations?: number): number;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getHashedPercentateForObjIds = void 0;
|
|
7
|
-
const md5_1 = __importDefault(require("md5"));
|
|
8
|
-
const big_integer_1 = __importDefault(require("big-integer"));
|
|
9
|
-
// def get_hashed_percentage_for_object_ids(
|
|
10
|
-
// object_ids: typing.Iterable[typing.Any], iterations: int = 1
|
|
11
|
-
// ) -> float:
|
|
12
|
-
// """
|
|
13
|
-
// Given a list of object ids, get a floating point number between 0 and 1 based on
|
|
14
|
-
// the hash of those ids. This should give the same value every time for any
|
|
15
|
-
// list of ids.
|
|
16
|
-
// :param object_ids: list of object ids to calculate the has for
|
|
17
|
-
// :param iterations: num times to include each id in the generated string to hash
|
|
18
|
-
// :return: (float) number between 0 (inclusive) and 100 (exclusive)
|
|
19
|
-
// """
|
|
20
|
-
const makeRepeated = (arr, repeats) => Array.from({ length: repeats }, () => arr).flat();
|
|
21
|
-
function h2d(s) {
|
|
22
|
-
function add(x, y) {
|
|
23
|
-
var c = 0, r = [];
|
|
24
|
-
var x = x.split('').map(Number);
|
|
25
|
-
var y = y.split('').map(Number);
|
|
26
|
-
while (x.length || y.length) {
|
|
27
|
-
var s = (x.pop() || 0) + (y.pop() || 0) + c;
|
|
28
|
-
r.unshift(s < 10 ? s : s - 10);
|
|
29
|
-
c = s < 10 ? 0 : 1;
|
|
30
|
-
}
|
|
31
|
-
if (c)
|
|
32
|
-
r.unshift(c);
|
|
33
|
-
return r.join('');
|
|
34
|
-
}
|
|
35
|
-
var dec = '0';
|
|
36
|
-
s.split('').forEach(function (chr) {
|
|
37
|
-
var n = parseInt(chr, 16);
|
|
38
|
-
for (var t = 8; t; t >>= 1) {
|
|
39
|
-
dec = add(dec, dec);
|
|
40
|
-
if (n & t)
|
|
41
|
-
dec = add(dec, '1');
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return dec;
|
|
45
|
-
}
|
|
46
|
-
function getHashedPercentateForObjIds(objectIds, iterations = 1) {
|
|
47
|
-
let to_hash = makeRepeated(objectIds, iterations).join(',');
|
|
48
|
-
const hashedValue = (0, md5_1.default)(to_hash);
|
|
49
|
-
const hashedInt = (0, big_integer_1.default)(h2d(hashedValue));
|
|
50
|
-
const value = (hashedInt.mod(9999).toJSNumber() / 9998) * 100;
|
|
51
|
-
if (value === 100) {
|
|
52
|
-
return getHashedPercentateForObjIds(objectIds, iterations + 1);
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
exports.getHashedPercentateForObjIds = getHashedPercentateForObjIds;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCastingFunction(input: any): CallableFunction;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCastingFunction = void 0;
|
|
4
|
-
function getCastingFunction(input) {
|
|
5
|
-
switch (typeof input) {
|
|
6
|
-
case 'boolean':
|
|
7
|
-
return (x) => !['False', 'false'].includes(x);
|
|
8
|
-
case 'number':
|
|
9
|
-
return (x) => parseFloat(x);
|
|
10
|
-
default:
|
|
11
|
-
return (x) => String(x);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.getCastingFunction = getCastingFunction;
|
package/build/index.d.ts
DELETED
package/build/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const sdk_1 = __importDefault(require("./sdk"));
|
|
7
|
-
exports.default = sdk_1.default;
|
package/build/sdk/analytics.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare class AnalyticsProcessor {
|
|
2
|
-
private analyticsEndpoint;
|
|
3
|
-
private environmentKey;
|
|
4
|
-
private lastFlushed;
|
|
5
|
-
analyticsData: {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
};
|
|
8
|
-
private timeout;
|
|
9
|
-
/**
|
|
10
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
11
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
12
|
-
*
|
|
13
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
14
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
15
|
-
* @param data.timeout used to tell requests to stop waiting for a response after a
|
|
16
|
-
given number of seconds
|
|
17
|
-
*/
|
|
18
|
-
constructor(data: {
|
|
19
|
-
environmentKey: string;
|
|
20
|
-
baseApiUrl: string;
|
|
21
|
-
timeout?: number;
|
|
22
|
-
});
|
|
23
|
-
/**
|
|
24
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
25
|
-
*/
|
|
26
|
-
flush(): Promise<void>;
|
|
27
|
-
trackFeature(featureId: number): void;
|
|
28
|
-
}
|
package/build/sdk/analytics.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AnalyticsProcessor = void 0;
|
|
7
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
-
const ANALYTICS_ENDPOINT = 'analytics/flags/';
|
|
9
|
-
// Used to control how often we send data(in seconds)
|
|
10
|
-
const ANALYTICS_TIMER = 10;
|
|
11
|
-
const delay = (ms) => new Promise(resolve => setTimeout(() => resolve(undefined), ms));
|
|
12
|
-
const retryFetch = (url, fetchOptions = {}, retries = 3, retryDelay = 1000, timeout) => {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
// check for timeout
|
|
15
|
-
if (timeout)
|
|
16
|
-
setTimeout(() => reject('error: timeout'), timeout);
|
|
17
|
-
const wrapper = (n) => {
|
|
18
|
-
(0, node_fetch_1.default)(url, fetchOptions)
|
|
19
|
-
.then(res => resolve(res))
|
|
20
|
-
.catch(async (err) => {
|
|
21
|
-
if (n > 0) {
|
|
22
|
-
await delay(retryDelay);
|
|
23
|
-
wrapper(--n);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
reject(err);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
wrapper(retries);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
class AnalyticsProcessor {
|
|
34
|
-
analyticsEndpoint;
|
|
35
|
-
environmentKey;
|
|
36
|
-
lastFlushed;
|
|
37
|
-
analyticsData;
|
|
38
|
-
timeout = 3;
|
|
39
|
-
/**
|
|
40
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
41
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
42
|
-
*
|
|
43
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
44
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
45
|
-
* @param data.timeout used to tell requests to stop waiting for a response after a
|
|
46
|
-
given number of seconds
|
|
47
|
-
*/
|
|
48
|
-
constructor(data) {
|
|
49
|
-
this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
|
|
50
|
-
this.environmentKey = data.environmentKey;
|
|
51
|
-
this.lastFlushed = Date.now();
|
|
52
|
-
this.analyticsData = {};
|
|
53
|
-
this.timeout = data.timeout || this.timeout;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
57
|
-
*/
|
|
58
|
-
async flush() {
|
|
59
|
-
if (!Object.keys(this.analyticsData).length) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
await (0, node_fetch_1.default)(this.analyticsEndpoint, {
|
|
63
|
-
method: 'POST',
|
|
64
|
-
body: JSON.stringify(this.analyticsData),
|
|
65
|
-
timeout: this.timeout,
|
|
66
|
-
headers: {
|
|
67
|
-
'Content-Type': 'application/json',
|
|
68
|
-
'X-Environment-Key': this.environmentKey
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
this.analyticsData = {};
|
|
72
|
-
this.lastFlushed = Date.now();
|
|
73
|
-
}
|
|
74
|
-
trackFeature(featureId) {
|
|
75
|
-
this.analyticsData[featureId] = (this.analyticsData[featureId] || 0) + 1;
|
|
76
|
-
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
|
|
77
|
-
this.flush();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.AnalyticsProcessor = AnalyticsProcessor;
|
package/build/sdk/errors.d.ts
DELETED
package/build/sdk/errors.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlagsmithAPIError = exports.FlagsmithClientError = void 0;
|
|
4
|
-
class FlagsmithClientError extends Error {
|
|
5
|
-
}
|
|
6
|
-
exports.FlagsmithClientError = FlagsmithClientError;
|
|
7
|
-
class FlagsmithAPIError extends Error {
|
|
8
|
-
}
|
|
9
|
-
exports.FlagsmithAPIError = FlagsmithAPIError;
|