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
package/sdk/models.ts
CHANGED
|
@@ -123,7 +123,9 @@ export class Flags {
|
|
|
123
123
|
if (this.defaultFlagHandler) {
|
|
124
124
|
return this.defaultFlagHandler(featureName);
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
|
|
127
|
+
return { enabled: false, isDefault: true, value: undefined };
|
|
128
|
+
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
if (this.analyticsProcessor && flag.featureId) {
|
package/sdk/polling_manager.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Flagsmith from '.';
|
|
2
2
|
|
|
3
3
|
export class EnvironmentDataPollingManager {
|
|
4
4
|
private interval?: NodeJS.Timer;
|
|
@@ -12,14 +12,14 @@ export class EnvironmentDataPollingManager {
|
|
|
12
12
|
|
|
13
13
|
start() {
|
|
14
14
|
const updateEnvironment = () => {
|
|
15
|
-
if(this.interval) clearInterval(this.interval)
|
|
15
|
+
if (this.interval) clearInterval(this.interval);
|
|
16
16
|
this.interval = setInterval(async () => {
|
|
17
17
|
await this.main.updateEnvironment();
|
|
18
18
|
}, this.refreshIntervalSeconds * 1000);
|
|
19
19
|
};
|
|
20
20
|
// todo: this call should be awaited for getIdentityFlags/getEnvironmentFlags when enableLocalEvaluation is true
|
|
21
|
-
this.main.updateEnvironment()
|
|
22
|
-
updateEnvironment()
|
|
21
|
+
this.main.updateEnvironment();
|
|
22
|
+
updateEnvironment();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
stop() {
|
package/sdk/utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import fetch, { Response } from 'node-fetch';
|
|
|
3
3
|
if (typeof fetch.default !== 'undefined') fetch = fetch.default;
|
|
4
4
|
|
|
5
5
|
export function generateIdentitiesData(identifier: string, traits?: { [key: string]: any }) {
|
|
6
|
-
const traitsGenerated = Object.
|
|
6
|
+
const traitsGenerated = Object.entries(traits || {}).map(trait => ({
|
|
7
7
|
trait_key: trait[0],
|
|
8
8
|
trait_value: trait[1]
|
|
9
9
|
}));
|
|
@@ -11,7 +11,44 @@
|
|
|
11
11
|
},
|
|
12
12
|
"id": 1,
|
|
13
13
|
"hide_disabled_flags": false,
|
|
14
|
-
"segments": [
|
|
14
|
+
"segments": [
|
|
15
|
+
{
|
|
16
|
+
"name": "regular_segment",
|
|
17
|
+
"feature_states": [
|
|
18
|
+
{
|
|
19
|
+
"feature_state_value": "segment_override",
|
|
20
|
+
"multivariate_feature_state_values": [],
|
|
21
|
+
"django_id": 81027,
|
|
22
|
+
"feature": {
|
|
23
|
+
"name": "some_feature",
|
|
24
|
+
"type": "STANDARD",
|
|
25
|
+
"id": 1
|
|
26
|
+
},
|
|
27
|
+
"enabled": false
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"id": 1,
|
|
31
|
+
"rules": [
|
|
32
|
+
{
|
|
33
|
+
"type": "ALL",
|
|
34
|
+
"conditions": [],
|
|
35
|
+
"rules": [
|
|
36
|
+
{
|
|
37
|
+
"type": "ANY",
|
|
38
|
+
"conditions": [
|
|
39
|
+
{
|
|
40
|
+
"value": "40",
|
|
41
|
+
"property_": "age",
|
|
42
|
+
"operator": "LESS_THAN"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"rules": []
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
15
52
|
},
|
|
16
53
|
"segment_overrides": [],
|
|
17
54
|
"id": 1,
|
|
@@ -30,4 +67,4 @@
|
|
|
30
67
|
"enabled": true
|
|
31
68
|
}
|
|
32
69
|
]
|
|
33
|
-
}
|
|
70
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Flagsmith from '../../sdk';
|
|
2
2
|
import { EnvironmentDataPollingManager } from '../../sdk/polling_manager';
|
|
3
3
|
import fetch, { Headers } from 'node-fetch';
|
|
4
4
|
import { environmentJSON, environmentModel, flagsJSON, flagsmith, identitiesJSON } from './utils';
|
|
@@ -14,8 +14,10 @@ beforeEach(() => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('test_flagsmith_starts_polling_manager_on_init_if_enabled', () => {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
fetch.mockReturnValue(Promise.resolve(new Response(environmentJSON())));
|
|
17
19
|
new Flagsmith({
|
|
18
|
-
environmentKey: 'key',
|
|
20
|
+
environmentKey: 'ser.key',
|
|
19
21
|
enableLocalEvaluation: true
|
|
20
22
|
});
|
|
21
23
|
expect(EnvironmentDataPollingManager).toBeCalled();
|
|
@@ -31,11 +33,28 @@ test('test_update_environment_sets_environment', async () => {
|
|
|
31
33
|
// @ts-ignore
|
|
32
34
|
flg.environment.featureStates[0].featurestateUUID = undefined;
|
|
33
35
|
// @ts-ignore
|
|
36
|
+
flg.environment.project.segments[0].featureStates[0].featurestateUUID = undefined;
|
|
37
|
+
// @ts-ignore
|
|
34
38
|
const model = environmentModel(JSON.parse(environmentJSON()));
|
|
35
39
|
// @ts-ignore
|
|
36
40
|
model.featureStates[0].featurestateUUID = undefined;
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
model.project.segments[0].featureStates[0].featurestateUUID = undefined;
|
|
37
43
|
expect(flg.environment).toStrictEqual(model);
|
|
38
44
|
});
|
|
45
|
+
|
|
46
|
+
test('test_get_identity_segments', async () => {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
fetch.mockReturnValue(Promise.resolve(new Response(environmentJSON())));
|
|
49
|
+
const flg = new Flagsmith({
|
|
50
|
+
environmentKey: 'ser.key',
|
|
51
|
+
enableLocalEvaluation: true
|
|
52
|
+
});
|
|
53
|
+
const segments = await flg.getIdentitySegments('user', { age: 21 });
|
|
54
|
+
expect(segments[0].name).toEqual('regular_segment');
|
|
55
|
+
const segments2 = await flg.getIdentitySegments('user', { age: 41 });
|
|
56
|
+
expect(segments2.length).toEqual(0);
|
|
57
|
+
});
|
|
39
58
|
test('test_get_environment_flags_calls_api_when_no_local_environment', async () => {
|
|
40
59
|
// @ts-ignore
|
|
41
60
|
fetch.mockReturnValue(Promise.resolve(new Response(flagsJSON())));
|
package/tests/sdk/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { buildEnvironmentModel } from '../../flagsmith-engine/environments/util';
|
|
3
3
|
import { AnalyticsProcessor } from '../../sdk/analytics';
|
|
4
|
-
import
|
|
4
|
+
import Flagsmith from '../../sdk';
|
|
5
5
|
|
|
6
6
|
const DATA_DIR = __dirname + '/data/';
|
|
7
7
|
|
|
@@ -1,12 +0,0 @@
|
|
|
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>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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, created_at: number, name: string, client_api_key: string, expires_at?: 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, api_key: string, project: ProjectModel);
|
|
25
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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, created_at, name, client_api_key, expires_at) {
|
|
13
|
-
this.id = id;
|
|
14
|
-
this.key = key;
|
|
15
|
-
this.createdAt = created_at;
|
|
16
|
-
this.name = name;
|
|
17
|
-
this.clientApiKey = client_api_key;
|
|
18
|
-
this.expiresAt = expires_at;
|
|
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, api_key, project) {
|
|
35
|
-
this.id = id;
|
|
36
|
-
this.apiKey = api_key;
|
|
37
|
-
this.project = project;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.EnvironmentModel = EnvironmentModel;
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
_value: any;
|
|
26
|
-
multivariateFeatureStateValues: MultivariateFeatureStateValueModel[];
|
|
27
|
-
constructor(feature: FeatureModel, enabled: boolean, djangoID: number, value?: any, featurestate_uuid?: 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
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
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, featurestate_uuid = (0, uuid_1.v4)()) {
|
|
50
|
-
this.feature = feature;
|
|
51
|
-
this.enabled = enabled;
|
|
52
|
-
this.djangoID = djangoID;
|
|
53
|
-
this._value = value;
|
|
54
|
-
this.featurestateUUID = featurestate_uuid;
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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, identity_traits: TraitModel[], identity_features: IdentityFeaturesList, environment_api_key: string, identifier: string, identity_uuid?: string);
|
|
12
|
-
get compositeKey(): string;
|
|
13
|
-
static generateCompositeKey(env_key: string, identifier: string): string;
|
|
14
|
-
update_traits(traits: TraitModel[]): void;
|
|
15
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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, identity_traits, identity_features, environment_api_key, identifier, identity_uuid) {
|
|
15
|
-
this.identityUuid = identity_uuid || uuidv4();
|
|
16
|
-
this.createdDate = Date.parse(created_date) || Date.now();
|
|
17
|
-
this.identityTraits = identity_traits;
|
|
18
|
-
this.identityFeatures = new collections_1.IdentityFeaturesList(...identity_features);
|
|
19
|
-
this.environmentApiKey = environment_api_key;
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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, feature_name: string, override_traits?: 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[];
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
function getIdentityFeatureStatesDict(environment, identity, override_traits) {
|
|
6
|
-
// Get feature states from the environment
|
|
7
|
-
const feature_states = {};
|
|
8
|
-
for (const fs of environment.featureStates) {
|
|
9
|
-
feature_states[fs.feature.id] = fs;
|
|
10
|
-
}
|
|
11
|
-
// Override with any feature states defined by matching segments
|
|
12
|
-
const identity_segments = (0, evaluators_1.getIdentitySegments)(environment, identity, override_traits);
|
|
13
|
-
for (const matching_segment of identity_segments) {
|
|
14
|
-
for (const feature_state of matching_segment.featureStates) {
|
|
15
|
-
// note that feature states are stored on the segment in descending priority
|
|
16
|
-
// order so we only care that the last one is added
|
|
17
|
-
// TODO: can we optimise this?
|
|
18
|
-
feature_states[feature_state.feature.id] = feature_state;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// Override with any feature states defined directly the identity
|
|
22
|
-
for (const fs of identity.identityFeatures || []) {
|
|
23
|
-
if (feature_states[fs.feature.id]) {
|
|
24
|
-
feature_states[fs.feature.id] = fs;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return feature_states;
|
|
28
|
-
}
|
|
29
|
-
function getIdentityFeatureState(environment, identity, feature_name, override_traits) {
|
|
30
|
-
const featureStates = getIdentityFeatureStatesDict(environment, identity, override_traits);
|
|
31
|
-
const matchingFeature = Object.values(featureStates).filter(f => f.feature.name === feature_name);
|
|
32
|
-
if (matchingFeature.length === 0) {
|
|
33
|
-
throw new Error('Feature State Not Found');
|
|
34
|
-
}
|
|
35
|
-
return matchingFeature[0];
|
|
36
|
-
}
|
|
37
|
-
exports.getIdentityFeatureState = getIdentityFeatureState;
|
|
38
|
-
function getIdentityFeatureStates(environment, identity, overrideTraits) {
|
|
39
|
-
const feature_states = Object.values(getIdentityFeatureStatesDict(environment, identity, overrideTraits));
|
|
40
|
-
if (environment.project.hideDisabledFlags) {
|
|
41
|
-
return feature_states.filter(fs => !!fs.enabled);
|
|
42
|
-
}
|
|
43
|
-
return feature_states;
|
|
44
|
-
}
|
|
45
|
-
exports.getIdentityFeatureStates = getIdentityFeatureStates;
|
|
46
|
-
function getEnvironmentFeatureState(environment, featureName) {
|
|
47
|
-
const featuresStates = environment.featureStates.filter(f => f.feature.name === featureName);
|
|
48
|
-
if (featuresStates.length === 0) {
|
|
49
|
-
throw new Error('Feature State Not Found');
|
|
50
|
-
}
|
|
51
|
-
return featuresStates[0];
|
|
52
|
-
}
|
|
53
|
-
exports.getEnvironmentFeatureState = getEnvironmentFeatureState;
|
|
54
|
-
function getEnvironmentFeatureStates(environment) {
|
|
55
|
-
if (environment.project.hideDisabledFlags) {
|
|
56
|
-
return environment.featureStates.filter(fs => !!fs.enabled);
|
|
57
|
-
}
|
|
58
|
-
return environment.featureStates;
|
|
59
|
-
}
|
|
60
|
-
exports.getEnvironmentFeatureStates = getEnvironmentFeatureStates;
|
|
@@ -1,9 +0,0 @@
|
|
|
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, feature_analytics: boolean, stop_serving_flags: boolean, persist_trait_data: boolean);
|
|
8
|
-
get unique_slug(): string;
|
|
9
|
-
}
|