flagsmith-nodejs 1.0.9 → 2.0.0-beta.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/.github/workflows/pull_request.yaml +33 -0
- package/.gitmodules +3 -0
- package/.husky/pre-commit +6 -0
- package/.idea/flagsmith-nodejs-client.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.prettierignore +1 -0
- package/.prettierrc.js +9 -0
- package/CONTRIBUTING.md +5 -4
- package/{LICENCE.md → LICENCE} +5 -6
- package/README.md +1 -1
- 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 +60 -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 +18 -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/hashing/index.d.ts +1 -0
- package/build/flagsmith-engine/utils/hashing/index.js +56 -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 +2 -0
- package/build/index.js +7 -0
- package/build/sdk/analytics.d.ts +28 -0
- package/build/sdk/analytics.js +81 -0
- package/build/sdk/errors.d.ts +4 -0
- package/build/sdk/errors.js +9 -0
- package/build/sdk/index.d.ts +99 -0
- package/build/sdk/index.js +221 -0
- package/build/sdk/models.d.ts +55 -0
- package/build/sdk/models.js +102 -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/example/README.md +8 -14
- package/example/package-lock.json +12 -12
- package/example/package.json +4 -4
- package/example/server/api/index.js +19 -22
- package/example/server/index.js +4 -9
- package/flagsmith-engine/environments/integrations/models.ts +4 -0
- package/flagsmith-engine/environments/models.ts +50 -0
- package/flagsmith-engine/environments/util.ts +29 -0
- package/flagsmith-engine/features/constants.ts +4 -0
- package/flagsmith-engine/features/models.ts +105 -0
- package/flagsmith-engine/features/util.ts +38 -0
- package/flagsmith-engine/identities/models.ts +60 -0
- package/flagsmith-engine/identities/traits/models.ts +9 -0
- package/flagsmith-engine/identities/util.ts +30 -0
- package/flagsmith-engine/index.ts +92 -0
- package/flagsmith-engine/organisations/models.ts +25 -0
- package/flagsmith-engine/organisations/util.ts +11 -0
- package/flagsmith-engine/projects/models.ts +23 -0
- package/flagsmith-engine/projects/util.ts +18 -0
- package/flagsmith-engine/segments/constants.ts +31 -0
- package/flagsmith-engine/segments/evaluators.ts +72 -0
- package/flagsmith-engine/segments/models.ts +103 -0
- package/flagsmith-engine/segments/util.ts +29 -0
- package/flagsmith-engine/utils/collections.ts +14 -0
- package/flagsmith-engine/utils/hashing/index.ts +57 -0
- package/flagsmith-engine/utils/index.ts +10 -0
- package/index.ts +3 -0
- package/jest.config.js +5 -0
- package/package.json +24 -3
- package/sdk/analytics.ts +88 -0
- package/sdk/errors.ts +2 -0
- package/sdk/index.ts +282 -0
- package/sdk/models.ts +143 -0
- package/sdk/polling_manager.ts +31 -0
- package/sdk/utils.ts +45 -0
- package/tests/engine/e2e/engine.test.ts +51 -0
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +12393 -0
- package/tests/engine/engine-tests/engine-test-data/readme.md +30 -0
- package/tests/engine/unit/egine.test.ts +96 -0
- package/tests/engine/unit/environments/builder.test.ts +148 -0
- package/tests/engine/unit/environments/models.test.ts +49 -0
- package/tests/engine/unit/features/models.test.ts +72 -0
- package/tests/engine/unit/identities/identities_builders.test.ts +85 -0
- package/tests/engine/unit/identities/identities_models.test.ts +105 -0
- package/tests/engine/unit/organization/models.test.ts +12 -0
- package/tests/engine/unit/segments/segments_model.test.ts +101 -0
- package/tests/engine/unit/segments/util.ts +151 -0
- package/tests/engine/unit/utils.ts +114 -0
- package/tests/index.js +0 -0
- package/tests/sdk/analytics.test.ts +43 -0
- package/tests/sdk/data/environment.json +33 -0
- package/tests/sdk/data/flags.json +20 -0
- package/tests/sdk/data/identities.json +29 -0
- package/tests/sdk/flagsmith.test.ts +184 -0
- package/tests/sdk/polling.test.ts +34 -0
- package/tests/sdk/utils.ts +39 -0
- package/tsconfig.json +19 -0
- package/flagsmith-core.js +0 -238
- package/index.d.ts +0 -78
- package/index.js +0 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Unit/Integration Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types:
|
|
6
|
+
- opened
|
|
7
|
+
- synchronize
|
|
8
|
+
- reopened
|
|
9
|
+
- ready_for_review
|
|
10
|
+
push:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
|
+
jobs:
|
|
14
|
+
build-and-test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v2
|
|
18
|
+
- uses: actions/setup-node@v1
|
|
19
|
+
with:
|
|
20
|
+
node-version: '15.x'
|
|
21
|
+
- name: cache node modules
|
|
22
|
+
uses: actions/cache@v1
|
|
23
|
+
with:
|
|
24
|
+
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
|
|
25
|
+
key: npm-${{ hashFiles('package-lock.json') }}
|
|
26
|
+
restore-keys: |
|
|
27
|
+
npm-${{ hashFiles('package-lock.json') }}
|
|
28
|
+
npm-
|
|
29
|
+
- run: npm i -g npm@7.0.2
|
|
30
|
+
- run: npm install
|
|
31
|
+
- run: npm test
|
|
32
|
+
env:
|
|
33
|
+
CI: true
|
package/.gitmodules
ADDED
|
@@ -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
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.json
|
package/.prettierrc.js
ADDED
package/CONTRIBUTING.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Contributing
|
|
2
|
+
|
|
2
3
|
We're always looking to improve this project, open source contribution is encouraged so long as they adhere to our guidelines.
|
|
3
4
|
|
|
4
5
|
# Pull Requests
|
|
@@ -7,7 +8,7 @@ The Solid State team will be monitoring for pull requests. When we get one, a me
|
|
|
7
8
|
|
|
8
9
|
**A couple things to keep in mind:**
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
- If you've changed APIs, update the documentation.
|
|
12
|
+
- Keep the code style (indents, wrapping) consistent.
|
|
13
|
+
- If your PR involves a lot of commits, squash them using `git rebase -i` as this makes it easier for us to review.
|
|
14
|
+
- Keep lines under 80 characters.
|
package/{LICENCE.md → LICENCE}
RENAMED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
All rights reserved.
|
|
1
|
+
Copyright 2022 Bullet Train Ltd. A UK company.
|
|
3
2
|
|
|
4
3
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
10
|
|
|
12
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -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, 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
|
+
}
|
|
@@ -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, 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;
|
|
@@ -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
|
+
_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
|
+
}
|
|
@@ -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, 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;
|
|
@@ -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, 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
|
+
}
|
|
@@ -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, 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;
|
|
@@ -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, 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[];
|
|
@@ -0,0 +1,60 @@
|
|
|
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;
|
|
@@ -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, feature_analytics: boolean, stop_serving_flags: boolean, persist_trait_data: 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, 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;
|
|
@@ -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;
|