flagsmith-nodejs 2.0.0-beta.4 → 2.0.0-beta.5
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/.idea/flagsmith-nodejs-client.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/build/flagsmith-engine/environments/integrations/models.d.ts +4 -0
- package/build/flagsmith-engine/environments/integrations/models.js +8 -0
- package/build/flagsmith-engine/environments/models.d.ts +25 -0
- package/build/flagsmith-engine/environments/models.js +40 -0
- package/build/flagsmith-engine/environments/util.d.ts +3 -0
- package/build/flagsmith-engine/environments/util.js +19 -0
- package/build/flagsmith-engine/features/constants.d.ts +4 -0
- package/build/flagsmith-engine/features/constants.js +7 -0
- package/build/flagsmith-engine/features/models.d.ts +32 -0
- package/build/flagsmith-engine/features/models.js +85 -0
- package/build/flagsmith-engine/features/util.d.ts +3 -0
- package/build/flagsmith-engine/features/util.js +20 -0
- package/build/flagsmith-engine/identities/models.d.ts +15 -0
- package/build/flagsmith-engine/identities/models.js +47 -0
- package/build/flagsmith-engine/identities/traits/models.d.ts +5 -0
- package/build/flagsmith-engine/identities/traits/models.js +12 -0
- package/build/flagsmith-engine/identities/util.d.ts +4 -0
- package/build/flagsmith-engine/identities/util.js +22 -0
- package/build/flagsmith-engine/index.d.ts +8 -0
- package/build/flagsmith-engine/index.js +61 -0
- package/build/flagsmith-engine/organisations/models.d.ts +9 -0
- package/build/flagsmith-engine/organisations/models.js +21 -0
- package/build/flagsmith-engine/organisations/util.d.ts +2 -0
- package/build/flagsmith-engine/organisations/util.js +8 -0
- package/build/flagsmith-engine/projects/models.d.ts +10 -0
- package/build/flagsmith-engine/projects/models.js +17 -0
- package/build/flagsmith-engine/projects/util.d.ts +2 -0
- package/build/flagsmith-engine/projects/util.js +15 -0
- package/build/flagsmith-engine/segments/constants.d.ts +26 -0
- package/build/flagsmith-engine/segments/constants.js +31 -0
- package/build/flagsmith-engine/segments/evaluators.d.ts +6 -0
- package/build/flagsmith-engine/segments/evaluators.js +29 -0
- package/build/flagsmith-engine/segments/models.d.ts +31 -0
- package/build/flagsmith-engine/segments/models.js +83 -0
- package/build/flagsmith-engine/segments/util.d.ts +4 -0
- package/build/flagsmith-engine/segments/util.js +23 -0
- package/build/flagsmith-engine/utils/collections.d.ts +4 -0
- package/build/flagsmith-engine/utils/collections.js +16 -0
- package/build/flagsmith-engine/utils/errors.d.ts +2 -0
- package/build/flagsmith-engine/utils/errors.js +6 -0
- package/build/flagsmith-engine/utils/hashing/index.d.ts +9 -0
- package/build/flagsmith-engine/utils/hashing/index.js +54 -0
- package/build/flagsmith-engine/utils/index.d.ts +1 -0
- package/build/flagsmith-engine/utils/index.js +14 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +11 -0
- package/build/sdk/analytics.d.ts +28 -0
- package/build/sdk/analytics.js +60 -0
- package/build/sdk/errors.d.ts +4 -0
- package/build/sdk/errors.js +9 -0
- package/build/sdk/index.d.ts +118 -0
- package/build/sdk/index.js +263 -0
- package/build/sdk/models.d.ts +55 -0
- package/build/sdk/models.js +101 -0
- package/build/sdk/polling_manager.d.ts +9 -0
- package/build/sdk/polling_manager.js +31 -0
- package/build/sdk/utils.d.ts +12 -0
- package/build/sdk/utils.js +45 -0
- package/package.json +1 -1
- package/.tool-versions +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/flagsmith-nodejs-client.iml" filepath="$PROJECT_DIR$/.idea/flagsmith-nodejs-client.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FeatureStateModel } from '../features/models';
|
|
2
|
+
import { ProjectModel } from '../projects/models';
|
|
3
|
+
import { IntegrationModel } from './integrations/models';
|
|
4
|
+
export declare class EnvironmentAPIKeyModel {
|
|
5
|
+
id: number;
|
|
6
|
+
key: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
name: string;
|
|
9
|
+
clientApiKey: string;
|
|
10
|
+
expiresAt?: number;
|
|
11
|
+
active: boolean;
|
|
12
|
+
constructor(id: number, key: string, createdAt: number, name: string, clientApiKey: string, expiresAt?: number);
|
|
13
|
+
isValid(): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare class EnvironmentModel {
|
|
16
|
+
id: number;
|
|
17
|
+
apiKey: string;
|
|
18
|
+
project: ProjectModel;
|
|
19
|
+
featureStates: FeatureStateModel[];
|
|
20
|
+
amplitude_config?: IntegrationModel;
|
|
21
|
+
segment_config?: IntegrationModel;
|
|
22
|
+
mixpanel_config?: IntegrationModel;
|
|
23
|
+
heap_config?: IntegrationModel;
|
|
24
|
+
constructor(id: number, apiKey: string, project: ProjectModel);
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentModel = exports.EnvironmentAPIKeyModel = void 0;
|
|
4
|
+
class EnvironmentAPIKeyModel {
|
|
5
|
+
id;
|
|
6
|
+
key;
|
|
7
|
+
createdAt;
|
|
8
|
+
name;
|
|
9
|
+
clientApiKey;
|
|
10
|
+
expiresAt;
|
|
11
|
+
active = true;
|
|
12
|
+
constructor(id, key, createdAt, name, clientApiKey, expiresAt) {
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.key = key;
|
|
15
|
+
this.createdAt = createdAt;
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.clientApiKey = clientApiKey;
|
|
18
|
+
this.expiresAt = expiresAt;
|
|
19
|
+
}
|
|
20
|
+
isValid() {
|
|
21
|
+
return !!this.active && (!this.expiresAt || this.expiresAt > Date.now());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.EnvironmentAPIKeyModel = EnvironmentAPIKeyModel;
|
|
25
|
+
class EnvironmentModel {
|
|
26
|
+
id;
|
|
27
|
+
apiKey;
|
|
28
|
+
project;
|
|
29
|
+
featureStates = [];
|
|
30
|
+
amplitude_config;
|
|
31
|
+
segment_config;
|
|
32
|
+
mixpanel_config;
|
|
33
|
+
heap_config;
|
|
34
|
+
constructor(id, apiKey, project) {
|
|
35
|
+
this.id = id;
|
|
36
|
+
this.apiKey = apiKey;
|
|
37
|
+
this.project = project;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.EnvironmentModel = EnvironmentModel;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildEnvironmentAPIKeyModel = exports.buildEnvironmentModel = void 0;
|
|
4
|
+
const util_1 = require("../features/util");
|
|
5
|
+
const util_2 = require("../projects/util");
|
|
6
|
+
const models_1 = require("./models");
|
|
7
|
+
function buildEnvironmentModel(environmentJSON) {
|
|
8
|
+
const project = (0, util_2.buildProjectModel)(environmentJSON.project);
|
|
9
|
+
const featureStates = environmentJSON.feature_states.map((fs) => (0, util_1.buildFeatureStateModel)(fs));
|
|
10
|
+
const environmentModel = new models_1.EnvironmentModel(environmentJSON.id, environmentJSON.api_key, project);
|
|
11
|
+
environmentModel.featureStates = featureStates;
|
|
12
|
+
return environmentModel;
|
|
13
|
+
}
|
|
14
|
+
exports.buildEnvironmentModel = buildEnvironmentModel;
|
|
15
|
+
function buildEnvironmentAPIKeyModel(apiKeyJSON) {
|
|
16
|
+
const model = new models_1.EnvironmentAPIKeyModel(apiKeyJSON.id, apiKeyJSON.key, Date.parse(apiKeyJSON.created_at), apiKeyJSON.name, apiKeyJSON.client_api_key);
|
|
17
|
+
return model;
|
|
18
|
+
}
|
|
19
|
+
exports.buildEnvironmentAPIKeyModel = buildEnvironmentAPIKeyModel;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class FeatureModel {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
constructor(id: number, name: string, type: string);
|
|
6
|
+
eq(other: FeatureModel): boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class MultivariateFeatureOptionModel {
|
|
9
|
+
value: any;
|
|
10
|
+
id: number | undefined;
|
|
11
|
+
constructor(value: any, id?: number);
|
|
12
|
+
}
|
|
13
|
+
export declare class MultivariateFeatureStateValueModel {
|
|
14
|
+
multivariateFeatureOption: MultivariateFeatureOptionModel;
|
|
15
|
+
percentageAllocation: number;
|
|
16
|
+
id: number;
|
|
17
|
+
mvFsValueUuid: string;
|
|
18
|
+
constructor(multivariate_feature_option: MultivariateFeatureOptionModel, percentage_allocation: number, id: number, mvFsValueUuid?: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class FeatureStateModel {
|
|
21
|
+
feature: FeatureModel;
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
djangoID: number;
|
|
24
|
+
featurestateUUID: string;
|
|
25
|
+
private value;
|
|
26
|
+
multivariateFeatureStateValues: MultivariateFeatureStateValueModel[];
|
|
27
|
+
constructor(feature: FeatureModel, enabled: boolean, djangoID: number, value?: any, featurestateUuid?: string);
|
|
28
|
+
setValue(value: any): void;
|
|
29
|
+
getValue(identityId?: number | string): any;
|
|
30
|
+
get_feature_state_value(): any;
|
|
31
|
+
getMultivariateValue(identityID: number | string): any;
|
|
32
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeatureStateModel = exports.MultivariateFeatureStateValueModel = exports.MultivariateFeatureOptionModel = exports.FeatureModel = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const hashing_1 = require("../utils/hashing");
|
|
6
|
+
class FeatureModel {
|
|
7
|
+
id;
|
|
8
|
+
name;
|
|
9
|
+
type;
|
|
10
|
+
constructor(id, name, type) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.type = type;
|
|
14
|
+
}
|
|
15
|
+
eq(other) {
|
|
16
|
+
return !!other && this.id === other.id;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FeatureModel = FeatureModel;
|
|
20
|
+
class MultivariateFeatureOptionModel {
|
|
21
|
+
value;
|
|
22
|
+
id;
|
|
23
|
+
constructor(value, id) {
|
|
24
|
+
this.value = value;
|
|
25
|
+
this.id = id;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.MultivariateFeatureOptionModel = MultivariateFeatureOptionModel;
|
|
29
|
+
class MultivariateFeatureStateValueModel {
|
|
30
|
+
multivariateFeatureOption;
|
|
31
|
+
percentageAllocation;
|
|
32
|
+
id;
|
|
33
|
+
mvFsValueUuid = (0, uuid_1.v4)();
|
|
34
|
+
constructor(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
|
|
35
|
+
this.id = id;
|
|
36
|
+
this.percentageAllocation = percentage_allocation;
|
|
37
|
+
this.multivariateFeatureOption = multivariate_feature_option;
|
|
38
|
+
this.mvFsValueUuid = mvFsValueUuid || this.mvFsValueUuid;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.MultivariateFeatureStateValueModel = MultivariateFeatureStateValueModel;
|
|
42
|
+
class FeatureStateModel {
|
|
43
|
+
feature;
|
|
44
|
+
enabled;
|
|
45
|
+
djangoID;
|
|
46
|
+
featurestateUUID = (0, uuid_1.v4)();
|
|
47
|
+
value;
|
|
48
|
+
multivariateFeatureStateValues = [];
|
|
49
|
+
constructor(feature, enabled, djangoID, value, featurestateUuid = (0, uuid_1.v4)()) {
|
|
50
|
+
this.feature = feature;
|
|
51
|
+
this.enabled = enabled;
|
|
52
|
+
this.djangoID = djangoID;
|
|
53
|
+
this.value = value;
|
|
54
|
+
this.featurestateUUID = featurestateUuid;
|
|
55
|
+
}
|
|
56
|
+
setValue(value) {
|
|
57
|
+
this.value = value;
|
|
58
|
+
}
|
|
59
|
+
getValue(identityId) {
|
|
60
|
+
if (!!identityId && this.multivariateFeatureStateValues.length > 0) {
|
|
61
|
+
return this.getMultivariateValue(identityId);
|
|
62
|
+
}
|
|
63
|
+
return this.value;
|
|
64
|
+
}
|
|
65
|
+
get_feature_state_value() {
|
|
66
|
+
return this.getValue();
|
|
67
|
+
}
|
|
68
|
+
getMultivariateValue(identityID) {
|
|
69
|
+
const percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
|
|
70
|
+
this.djangoID || this.featurestateUUID,
|
|
71
|
+
identityID
|
|
72
|
+
]);
|
|
73
|
+
let startPercentage = 0;
|
|
74
|
+
const sortedF = this.multivariateFeatureStateValues.sort((a, b) => !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1);
|
|
75
|
+
for (const myValue of sortedF) {
|
|
76
|
+
const limit = myValue.percentageAllocation + startPercentage;
|
|
77
|
+
if (startPercentage <= percentageValue && percentageValue < limit) {
|
|
78
|
+
return myValue.multivariateFeatureOption.value;
|
|
79
|
+
}
|
|
80
|
+
startPercentage = limit;
|
|
81
|
+
}
|
|
82
|
+
return this.value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.FeatureStateModel = FeatureStateModel;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
|
|
4
|
+
const models_1 = require("./models");
|
|
5
|
+
function buildFeatureModel(featuresModelJSON) {
|
|
6
|
+
return new models_1.FeatureModel(featuresModelJSON.id, featuresModelJSON.name, featuresModelJSON.type);
|
|
7
|
+
}
|
|
8
|
+
exports.buildFeatureModel = buildFeatureModel;
|
|
9
|
+
function buildFeatureStateModel(featuresStateModelJSON) {
|
|
10
|
+
const featureStateModel = new models_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.uuid);
|
|
11
|
+
const multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
|
|
12
|
+
? featuresStateModelJSON.multivariate_feature_state_values.map((fsv) => {
|
|
13
|
+
const featureOption = new models_1.MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
|
|
14
|
+
return new models_1.MultivariateFeatureStateValueModel(featureOption, fsv.percentage_allocation, fsv.id);
|
|
15
|
+
})
|
|
16
|
+
: [];
|
|
17
|
+
featureStateModel.multivariateFeatureStateValues = multivariateFeatureStateValues;
|
|
18
|
+
return featureStateModel;
|
|
19
|
+
}
|
|
20
|
+
exports.buildFeatureStateModel = buildFeatureStateModel;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IdentityFeaturesList } from '../utils/collections';
|
|
2
|
+
import { TraitModel } from './traits/models';
|
|
3
|
+
export declare class IdentityModel {
|
|
4
|
+
identifier: string;
|
|
5
|
+
environmentApiKey: string;
|
|
6
|
+
createdDate?: number;
|
|
7
|
+
identityFeatures: IdentityFeaturesList;
|
|
8
|
+
identityTraits: TraitModel[];
|
|
9
|
+
identityUuid: string;
|
|
10
|
+
djangoID: number | undefined;
|
|
11
|
+
constructor(created_date: string, identityTraits: TraitModel[], identityFeatures: IdentityFeaturesList, environmentApiKey: string, identifier: string, identityUuid?: string);
|
|
12
|
+
get compositeKey(): string;
|
|
13
|
+
static generateCompositeKey(env_key: string, identifier: string): string;
|
|
14
|
+
update_traits(traits: TraitModel[]): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentityModel = void 0;
|
|
4
|
+
const collections_1 = require("../utils/collections");
|
|
5
|
+
const { v4: uuidv4 } = require('uuid');
|
|
6
|
+
class IdentityModel {
|
|
7
|
+
identifier;
|
|
8
|
+
environmentApiKey;
|
|
9
|
+
createdDate;
|
|
10
|
+
identityFeatures;
|
|
11
|
+
identityTraits;
|
|
12
|
+
identityUuid;
|
|
13
|
+
djangoID;
|
|
14
|
+
constructor(created_date, identityTraits, identityFeatures, environmentApiKey, identifier, identityUuid) {
|
|
15
|
+
this.identityUuid = identityUuid || uuidv4();
|
|
16
|
+
this.createdDate = Date.parse(created_date) || Date.now();
|
|
17
|
+
this.identityTraits = identityTraits;
|
|
18
|
+
this.identityFeatures = new collections_1.IdentityFeaturesList(...identityFeatures);
|
|
19
|
+
this.environmentApiKey = environmentApiKey;
|
|
20
|
+
this.identifier = identifier;
|
|
21
|
+
}
|
|
22
|
+
get compositeKey() {
|
|
23
|
+
return IdentityModel.generateCompositeKey(this.environmentApiKey, this.identifier);
|
|
24
|
+
}
|
|
25
|
+
static generateCompositeKey(env_key, identifier) {
|
|
26
|
+
return `${env_key}_${identifier}`;
|
|
27
|
+
}
|
|
28
|
+
update_traits(traits) {
|
|
29
|
+
const existingTraits = new Map();
|
|
30
|
+
for (const trait of this.identityTraits) {
|
|
31
|
+
existingTraits.set(trait.traitKey, trait);
|
|
32
|
+
}
|
|
33
|
+
for (const trait of traits) {
|
|
34
|
+
if (!!trait.traitValue) {
|
|
35
|
+
existingTraits.set(trait.traitKey, trait);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
existingTraits.delete(trait.traitKey);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
this.identityTraits = [];
|
|
42
|
+
for (const [k, v] of existingTraits.entries()) {
|
|
43
|
+
this.identityTraits.push(v);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.IdentityModel = IdentityModel;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraitModel = void 0;
|
|
4
|
+
class TraitModel {
|
|
5
|
+
traitKey;
|
|
6
|
+
traitValue;
|
|
7
|
+
constructor(key, value) {
|
|
8
|
+
this.traitKey = key;
|
|
9
|
+
this.traitValue = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.TraitModel = TraitModel;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildIdentityModel = exports.buildTraitModel = void 0;
|
|
4
|
+
const util_1 = require("../features/util");
|
|
5
|
+
const collections_1 = require("../utils/collections");
|
|
6
|
+
const models_1 = require("./models");
|
|
7
|
+
const models_2 = require("./traits/models");
|
|
8
|
+
function buildTraitModel(traitJSON) {
|
|
9
|
+
return new models_2.TraitModel(traitJSON.trait_key, traitJSON.trait_value);
|
|
10
|
+
}
|
|
11
|
+
exports.buildTraitModel = buildTraitModel;
|
|
12
|
+
function buildIdentityModel(identityJSON) {
|
|
13
|
+
const featureList = identityJSON.identity_features
|
|
14
|
+
? new collections_1.IdentityFeaturesList(...identityJSON.identity_features.map((f) => (0, util_1.buildFeatureStateModel)(f)))
|
|
15
|
+
: [];
|
|
16
|
+
const model = new models_1.IdentityModel(identityJSON.created_date, identityJSON.identity_traits
|
|
17
|
+
? identityJSON.identity_traits.map((trait) => buildTraitModel(trait))
|
|
18
|
+
: [], featureList, identityJSON.environment_api_key, identityJSON.identifier, identityJSON.identity_uuid);
|
|
19
|
+
model.djangoID = identityJSON.django_id;
|
|
20
|
+
return model;
|
|
21
|
+
}
|
|
22
|
+
exports.buildIdentityModel = buildIdentityModel;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EnvironmentModel } from './environments/models';
|
|
2
|
+
import { FeatureStateModel } from './features/models';
|
|
3
|
+
import { IdentityModel } from './identities/models';
|
|
4
|
+
import { TraitModel } from './identities/traits/models';
|
|
5
|
+
export declare function getIdentityFeatureState(environment: EnvironmentModel, identity: IdentityModel, featureName: string, overrideTraits?: TraitModel[]): FeatureStateModel;
|
|
6
|
+
export declare function getIdentityFeatureStates(environment: EnvironmentModel, identity: IdentityModel, overrideTraits?: TraitModel[]): FeatureStateModel[];
|
|
7
|
+
export declare function getEnvironmentFeatureState(environment: EnvironmentModel, featureName: string): FeatureStateModel;
|
|
8
|
+
export declare function getEnvironmentFeatureStates(environment: EnvironmentModel): FeatureStateModel[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEnvironmentFeatureStates = exports.getEnvironmentFeatureState = exports.getIdentityFeatureStates = exports.getIdentityFeatureState = void 0;
|
|
4
|
+
const evaluators_1 = require("./segments/evaluators");
|
|
5
|
+
const errors_1 = require("./utils/errors");
|
|
6
|
+
function getIdentityFeatureStatesDict(environment, identity, overrideTraits) {
|
|
7
|
+
// Get feature states from the environment
|
|
8
|
+
const featureStates = {};
|
|
9
|
+
for (const fs of environment.featureStates) {
|
|
10
|
+
featureStates[fs.feature.id] = fs;
|
|
11
|
+
}
|
|
12
|
+
// Override with any feature states defined by matching segments
|
|
13
|
+
const identitySegments = (0, evaluators_1.getIdentitySegments)(environment, identity, overrideTraits);
|
|
14
|
+
for (const matchingSegment of identitySegments) {
|
|
15
|
+
for (const featureState of matchingSegment.featureStates) {
|
|
16
|
+
// note that feature states are stored on the segment in descending priority
|
|
17
|
+
// order so we only care that the last one is added
|
|
18
|
+
// TODO: can we optimise this?
|
|
19
|
+
featureStates[featureState.feature.id] = featureState;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Override with any feature states defined directly the identity
|
|
23
|
+
for (const fs of identity.identityFeatures || []) {
|
|
24
|
+
if (featureStates[fs.feature.id]) {
|
|
25
|
+
featureStates[fs.feature.id] = fs;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return featureStates;
|
|
29
|
+
}
|
|
30
|
+
function getIdentityFeatureState(environment, identity, featureName, overrideTraits) {
|
|
31
|
+
const featureStates = getIdentityFeatureStatesDict(environment, identity, overrideTraits);
|
|
32
|
+
const matchingFeature = Object.values(featureStates).filter(f => f.feature.name === featureName);
|
|
33
|
+
if (matchingFeature.length === 0) {
|
|
34
|
+
throw new errors_1.FeatureStateNotFound('Feature State Not Found');
|
|
35
|
+
}
|
|
36
|
+
return matchingFeature[0];
|
|
37
|
+
}
|
|
38
|
+
exports.getIdentityFeatureState = getIdentityFeatureState;
|
|
39
|
+
function getIdentityFeatureStates(environment, identity, overrideTraits) {
|
|
40
|
+
const featureStates = Object.values(getIdentityFeatureStatesDict(environment, identity, overrideTraits));
|
|
41
|
+
if (environment.project.hideDisabledFlags) {
|
|
42
|
+
return featureStates.filter(fs => !!fs.enabled);
|
|
43
|
+
}
|
|
44
|
+
return featureStates;
|
|
45
|
+
}
|
|
46
|
+
exports.getIdentityFeatureStates = getIdentityFeatureStates;
|
|
47
|
+
function getEnvironmentFeatureState(environment, featureName) {
|
|
48
|
+
const featuresStates = environment.featureStates.filter(f => f.feature.name === featureName);
|
|
49
|
+
if (featuresStates.length === 0) {
|
|
50
|
+
throw new Error('Feature State Not Found');
|
|
51
|
+
}
|
|
52
|
+
return featuresStates[0];
|
|
53
|
+
}
|
|
54
|
+
exports.getEnvironmentFeatureState = getEnvironmentFeatureState;
|
|
55
|
+
function getEnvironmentFeatureStates(environment) {
|
|
56
|
+
if (environment.project.hideDisabledFlags) {
|
|
57
|
+
return environment.featureStates.filter(fs => !!fs.enabled);
|
|
58
|
+
}
|
|
59
|
+
return environment.featureStates;
|
|
60
|
+
}
|
|
61
|
+
exports.getEnvironmentFeatureStates = getEnvironmentFeatureStates;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class OrganisationModel {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
featureAnalytics: boolean;
|
|
5
|
+
stopServingFlags: boolean;
|
|
6
|
+
persistTraitData: boolean;
|
|
7
|
+
constructor(id: number, name: string, featureAnalytics: boolean, stopServingFlags: boolean, persistTraitData: boolean);
|
|
8
|
+
get unique_slug(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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, featureAnalytics, stopServingFlags, persistTraitData) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.featureAnalytics = featureAnalytics;
|
|
14
|
+
this.stopServingFlags = stopServingFlags;
|
|
15
|
+
this.persistTraitData = persistTraitData;
|
|
16
|
+
}
|
|
17
|
+
get unique_slug() {
|
|
18
|
+
return this.id.toString() + '-' + this.name;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.OrganisationModel = OrganisationModel;
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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, hideDisabledFlags: boolean, organization: OrganisationModel);
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
segments = [];
|
|
10
|
+
constructor(id, name, hideDisabledFlags, organization) {
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.hideDisabledFlags = hideDisabledFlags;
|
|
14
|
+
this.organisation = organization;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ProjectModel = ProjectModel;
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|