flagsmith-nodejs 2.0.0-beta.4 → 2.0.0-beta.7
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 +37 -29
- package/.idea/flagsmith-nodejs-client.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +7 -0
- package/build/flagsmith-engine/environments/integrations/models.d.ts +4 -0
- package/build/flagsmith-engine/environments/integrations/models.js +11 -0
- package/build/flagsmith-engine/environments/models.d.ts +25 -0
- package/build/flagsmith-engine/environments/models.js +29 -0
- package/build/flagsmith-engine/environments/util.d.ts +3 -0
- package/build/flagsmith-engine/environments/util.js +21 -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 +31 -0
- package/build/flagsmith-engine/features/models.js +99 -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 +112 -0
- package/build/flagsmith-engine/identities/traits/models.d.ts +5 -0
- package/build/flagsmith-engine/identities/traits/models.js +11 -0
- package/build/flagsmith-engine/identities/util.d.ts +4 -0
- package/build/flagsmith-engine/identities/util.js +46 -0
- package/build/flagsmith-engine/index.d.ts +8 -0
- package/build/flagsmith-engine/index.js +113 -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 +14 -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 +37 -0
- package/build/flagsmith-engine/segments/models.d.ts +31 -0
- package/build/flagsmith-engine/segments/models.js +89 -0
- package/build/flagsmith-engine/segments/util.d.ts +4 -0
- package/build/flagsmith-engine/segments/util.js +25 -0
- package/build/flagsmith-engine/utils/collections.d.ts +3 -0
- package/build/flagsmith-engine/utils/collections.js +26 -0
- package/build/flagsmith-engine/utils/errors.d.ts +2 -0
- package/build/flagsmith-engine/utils/errors.js +26 -0
- package/build/flagsmith-engine/utils/hashing/index.d.ts +9 -0
- package/build/flagsmith-engine/utils/hashing/index.js +60 -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 +102 -0
- package/build/sdk/errors.d.ts +4 -0
- package/build/sdk/errors.js +34 -0
- package/build/sdk/index.d.ts +123 -0
- package/build/sdk/index.js +484 -0
- package/build/sdk/models.d.ts +55 -0
- package/build/sdk/models.js +149 -0
- package/build/sdk/polling_manager.d.ts +9 -0
- package/build/sdk/polling_manager.js +72 -0
- package/build/sdk/types.d.ts +7 -0
- package/build/sdk/types.js +2 -0
- package/build/sdk/utils.d.ts +12 -0
- package/build/sdk/utils.js +94 -0
- package/example/package-lock.json +1 -996
- package/flagsmith-engine/features/models.ts +0 -4
- package/flagsmith-engine/identities/models.ts +1 -1
- package/flagsmith-engine/index.ts +1 -1
- package/flagsmith-engine/organisations/models.ts +1 -1
- package/flagsmith-engine/segments/models.ts +0 -2
- package/flagsmith-engine/utils/collections.ts +1 -12
- package/flagsmith-engine/utils/hashing/index.ts +5 -2
- package/package.json +3 -2
- package/sdk/analytics.ts +0 -2
- package/sdk/index.ts +83 -26
- package/sdk/polling_manager.ts +0 -1
- package/sdk/types.ts +8 -0
- package/tests/engine/unit/{egine.test.ts → engine.test.ts} +20 -0
- package/tests/engine/unit/features/models.test.ts +7 -3
- package/tests/engine/unit/identities/identities_builders.test.ts +13 -0
- package/tests/engine/unit/identities/identities_models.test.ts +3 -14
- package/tests/engine/unit/organization/models.test.ts +1 -1
- package/tests/engine/unit/segments/segments_model.test.ts +2 -1
- package/tests/engine/unit/utils.ts +1 -1
- package/tests/sdk/analytics.test.ts +11 -0
- package/tests/sdk/flagsmith-cache.test.ts +150 -0
- package/tests/sdk/flagsmith-environment-flags.test.ts +197 -0
- package/tests/sdk/flagsmith-identity-flags.test.ts +140 -0
- package/tests/sdk/flagsmith.test.ts +100 -85
- package/tests/sdk/polling.test.ts +25 -0
- package/tests/sdk/utils.ts +21 -2
- package/tsconfig.json +2 -1
- package/.tool-versions +0 -1
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12393
- package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
name: Unit/Integration Tests
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
pull_request:
|
|
5
|
+
types:
|
|
6
|
+
- opened
|
|
7
|
+
- synchronize
|
|
8
|
+
- reopened
|
|
9
|
+
- ready_for_review
|
|
10
|
+
push:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
13
|
jobs:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
build-and-test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v2
|
|
18
|
+
- name: Checkout submodules # checkout rest
|
|
19
|
+
shell: bash
|
|
20
|
+
run: |
|
|
21
|
+
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
|
|
22
|
+
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
|
23
|
+
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
|
|
24
|
+
git submodule sync --recursive
|
|
25
|
+
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
|
|
26
|
+
- uses: actions/setup-node@v1
|
|
27
|
+
with:
|
|
28
|
+
node-version: "15.x"
|
|
29
|
+
- name: cache node modules
|
|
30
|
+
uses: actions/cache@v1
|
|
31
|
+
with:
|
|
32
|
+
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
|
|
33
|
+
key: npm-${{ hashFiles('package-lock.json') }}
|
|
34
|
+
restore-keys: |
|
|
35
|
+
npm-${{ hashFiles('package-lock.json') }}
|
|
36
|
+
npm-
|
|
37
|
+
- run: npm i -g npm@7.0.2
|
|
38
|
+
- run: npm install
|
|
39
|
+
- run: npm test
|
|
40
|
+
env:
|
|
41
|
+
CI: true
|
|
@@ -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/README.md
CHANGED
|
@@ -19,6 +19,13 @@ Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45c
|
|
|
19
19
|
|
|
20
20
|
If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.
|
|
21
21
|
|
|
22
|
+
## Testing
|
|
23
|
+
|
|
24
|
+
To run the local tests you need to run following command beforehand:
|
|
25
|
+
```
|
|
26
|
+
git submodule add git@github.com:Flagsmith/engine-test-data.git tests/engine/engine-tests/engine-test-data/
|
|
27
|
+
```
|
|
28
|
+
|
|
22
29
|
## Get in touch
|
|
23
30
|
|
|
24
31
|
If you have any questions about our projects you can email <a href="mailto:support@flagsmith.com">support@flagsmith.com</a>.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntegrationModel = void 0;
|
|
4
|
+
var IntegrationModel = /** @class */ (function () {
|
|
5
|
+
function IntegrationModel() {
|
|
6
|
+
this.api_key = undefined;
|
|
7
|
+
this.base_url = undefined;
|
|
8
|
+
}
|
|
9
|
+
return IntegrationModel;
|
|
10
|
+
}());
|
|
11
|
+
exports.IntegrationModel = IntegrationModel;
|
|
@@ -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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentModel = exports.EnvironmentAPIKeyModel = void 0;
|
|
4
|
+
var EnvironmentAPIKeyModel = /** @class */ (function () {
|
|
5
|
+
function EnvironmentAPIKeyModel(id, key, createdAt, name, clientApiKey, expiresAt) {
|
|
6
|
+
this.active = true;
|
|
7
|
+
this.id = id;
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.createdAt = createdAt;
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.clientApiKey = clientApiKey;
|
|
12
|
+
this.expiresAt = expiresAt;
|
|
13
|
+
}
|
|
14
|
+
EnvironmentAPIKeyModel.prototype.isValid = function () {
|
|
15
|
+
return !!this.active && (!this.expiresAt || this.expiresAt > Date.now());
|
|
16
|
+
};
|
|
17
|
+
return EnvironmentAPIKeyModel;
|
|
18
|
+
}());
|
|
19
|
+
exports.EnvironmentAPIKeyModel = EnvironmentAPIKeyModel;
|
|
20
|
+
var EnvironmentModel = /** @class */ (function () {
|
|
21
|
+
function EnvironmentModel(id, apiKey, project) {
|
|
22
|
+
this.featureStates = [];
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.apiKey = apiKey;
|
|
25
|
+
this.project = project;
|
|
26
|
+
}
|
|
27
|
+
return EnvironmentModel;
|
|
28
|
+
}());
|
|
29
|
+
exports.EnvironmentModel = EnvironmentModel;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildEnvironmentAPIKeyModel = exports.buildEnvironmentModel = void 0;
|
|
4
|
+
var util_1 = require("../features/util");
|
|
5
|
+
var util_2 = require("../projects/util");
|
|
6
|
+
var models_1 = require("./models");
|
|
7
|
+
function buildEnvironmentModel(environmentJSON) {
|
|
8
|
+
var project = (0, util_2.buildProjectModel)(environmentJSON.project);
|
|
9
|
+
var featureStates = environmentJSON.feature_states.map(function (fs) {
|
|
10
|
+
return (0, util_1.buildFeatureStateModel)(fs);
|
|
11
|
+
});
|
|
12
|
+
var environmentModel = new models_1.EnvironmentModel(environmentJSON.id, environmentJSON.api_key, project);
|
|
13
|
+
environmentModel.featureStates = featureStates;
|
|
14
|
+
return environmentModel;
|
|
15
|
+
}
|
|
16
|
+
exports.buildEnvironmentModel = buildEnvironmentModel;
|
|
17
|
+
function buildEnvironmentAPIKeyModel(apiKeyJSON) {
|
|
18
|
+
var model = new models_1.EnvironmentAPIKeyModel(apiKeyJSON.id, apiKeyJSON.key, Date.parse(apiKeyJSON.created_at), apiKeyJSON.name, apiKeyJSON.client_api_key);
|
|
19
|
+
return model;
|
|
20
|
+
}
|
|
21
|
+
exports.buildEnvironmentAPIKeyModel = buildEnvironmentAPIKeyModel;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
getMultivariateValue(identityID: number | string): any;
|
|
31
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.FeatureStateModel = exports.MultivariateFeatureStateValueModel = exports.MultivariateFeatureOptionModel = exports.FeatureModel = void 0;
|
|
15
|
+
var uuid_1 = require("uuid");
|
|
16
|
+
var hashing_1 = require("../utils/hashing");
|
|
17
|
+
var FeatureModel = /** @class */ (function () {
|
|
18
|
+
function FeatureModel(id, name, type) {
|
|
19
|
+
this.id = id;
|
|
20
|
+
this.name = name;
|
|
21
|
+
this.type = type;
|
|
22
|
+
}
|
|
23
|
+
FeatureModel.prototype.eq = function (other) {
|
|
24
|
+
return !!other && this.id === other.id;
|
|
25
|
+
};
|
|
26
|
+
return FeatureModel;
|
|
27
|
+
}());
|
|
28
|
+
exports.FeatureModel = FeatureModel;
|
|
29
|
+
var MultivariateFeatureOptionModel = /** @class */ (function () {
|
|
30
|
+
function MultivariateFeatureOptionModel(value, id) {
|
|
31
|
+
this.value = value;
|
|
32
|
+
this.id = id;
|
|
33
|
+
}
|
|
34
|
+
return MultivariateFeatureOptionModel;
|
|
35
|
+
}());
|
|
36
|
+
exports.MultivariateFeatureOptionModel = MultivariateFeatureOptionModel;
|
|
37
|
+
var MultivariateFeatureStateValueModel = /** @class */ (function () {
|
|
38
|
+
function MultivariateFeatureStateValueModel(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
|
|
39
|
+
this.mvFsValueUuid = (0, uuid_1.v4)();
|
|
40
|
+
this.id = id;
|
|
41
|
+
this.percentageAllocation = percentage_allocation;
|
|
42
|
+
this.multivariateFeatureOption = multivariate_feature_option;
|
|
43
|
+
this.mvFsValueUuid = mvFsValueUuid || this.mvFsValueUuid;
|
|
44
|
+
}
|
|
45
|
+
return MultivariateFeatureStateValueModel;
|
|
46
|
+
}());
|
|
47
|
+
exports.MultivariateFeatureStateValueModel = MultivariateFeatureStateValueModel;
|
|
48
|
+
var FeatureStateModel = /** @class */ (function () {
|
|
49
|
+
function FeatureStateModel(feature, enabled, djangoID, value, featurestateUuid) {
|
|
50
|
+
if (featurestateUuid === void 0) { featurestateUuid = (0, uuid_1.v4)(); }
|
|
51
|
+
this.featurestateUUID = (0, uuid_1.v4)();
|
|
52
|
+
this.multivariateFeatureStateValues = [];
|
|
53
|
+
this.feature = feature;
|
|
54
|
+
this.enabled = enabled;
|
|
55
|
+
this.djangoID = djangoID;
|
|
56
|
+
this.value = value;
|
|
57
|
+
this.featurestateUUID = featurestateUuid;
|
|
58
|
+
}
|
|
59
|
+
FeatureStateModel.prototype.setValue = function (value) {
|
|
60
|
+
this.value = value;
|
|
61
|
+
};
|
|
62
|
+
FeatureStateModel.prototype.getValue = function (identityId) {
|
|
63
|
+
if (!!identityId && this.multivariateFeatureStateValues.length > 0) {
|
|
64
|
+
return this.getMultivariateValue(identityId);
|
|
65
|
+
}
|
|
66
|
+
return this.value;
|
|
67
|
+
};
|
|
68
|
+
FeatureStateModel.prototype.getMultivariateValue = function (identityID) {
|
|
69
|
+
var e_1, _a;
|
|
70
|
+
var percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
|
|
71
|
+
this.djangoID || this.featurestateUUID,
|
|
72
|
+
identityID
|
|
73
|
+
]);
|
|
74
|
+
var startPercentage = 0;
|
|
75
|
+
var sortedF = this.multivariateFeatureStateValues.sort(function (a, b) {
|
|
76
|
+
return !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1;
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
for (var sortedF_1 = __values(sortedF), sortedF_1_1 = sortedF_1.next(); !sortedF_1_1.done; sortedF_1_1 = sortedF_1.next()) {
|
|
80
|
+
var myValue = sortedF_1_1.value;
|
|
81
|
+
var limit = myValue.percentageAllocation + startPercentage;
|
|
82
|
+
if (startPercentage <= percentageValue && percentageValue < limit) {
|
|
83
|
+
return myValue.multivariateFeatureOption.value;
|
|
84
|
+
}
|
|
85
|
+
startPercentage = limit;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
89
|
+
finally {
|
|
90
|
+
try {
|
|
91
|
+
if (sortedF_1_1 && !sortedF_1_1.done && (_a = sortedF_1.return)) _a.call(sortedF_1);
|
|
92
|
+
}
|
|
93
|
+
finally { if (e_1) throw e_1.error; }
|
|
94
|
+
}
|
|
95
|
+
return this.value;
|
|
96
|
+
};
|
|
97
|
+
return FeatureStateModel;
|
|
98
|
+
}());
|
|
99
|
+
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
|
+
var 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
|
+
var featureStateModel = new models_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.uuid);
|
|
11
|
+
var multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
|
|
12
|
+
? featuresStateModelJSON.multivariate_feature_state_values.map(function (fsv) {
|
|
13
|
+
var 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
|
+
updateTraits(traits: TraitModel[]): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
+
if (m) return m.call(o);
|
|
30
|
+
if (o && typeof o.length === "number") return {
|
|
31
|
+
next: function () {
|
|
32
|
+
if (o && i >= o.length) o = void 0;
|
|
33
|
+
return { value: o && o[i++], done: !o };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.IdentityModel = void 0;
|
|
40
|
+
var collections_1 = require("../utils/collections");
|
|
41
|
+
var uuidv4 = require('uuid').v4;
|
|
42
|
+
var IdentityModel = /** @class */ (function () {
|
|
43
|
+
function IdentityModel(created_date, identityTraits, identityFeatures, environmentApiKey, identifier, identityUuid) {
|
|
44
|
+
this.identityUuid = identityUuid || uuidv4();
|
|
45
|
+
this.createdDate = Date.parse(created_date) || Date.now();
|
|
46
|
+
this.identityTraits = identityTraits;
|
|
47
|
+
this.identityFeatures = new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityFeatures), false)))();
|
|
48
|
+
this.environmentApiKey = environmentApiKey;
|
|
49
|
+
this.identifier = identifier;
|
|
50
|
+
}
|
|
51
|
+
Object.defineProperty(IdentityModel.prototype, "compositeKey", {
|
|
52
|
+
get: function () {
|
|
53
|
+
return IdentityModel.generateCompositeKey(this.environmentApiKey, this.identifier);
|
|
54
|
+
},
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
IdentityModel.generateCompositeKey = function (env_key, identifier) {
|
|
59
|
+
return "".concat(env_key, "_").concat(identifier);
|
|
60
|
+
};
|
|
61
|
+
IdentityModel.prototype.updateTraits = function (traits) {
|
|
62
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
63
|
+
var existingTraits = new Map();
|
|
64
|
+
try {
|
|
65
|
+
for (var _d = __values(this.identityTraits), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
66
|
+
var trait = _e.value;
|
|
67
|
+
existingTraits.set(trait.traitKey, trait);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e_1) throw e_1.error; }
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
for (var traits_1 = __values(traits), traits_1_1 = traits_1.next(); !traits_1_1.done; traits_1_1 = traits_1.next()) {
|
|
79
|
+
var trait = traits_1_1.value;
|
|
80
|
+
if (!!trait.traitValue) {
|
|
81
|
+
existingTraits.set(trait.traitKey, trait);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
existingTraits.delete(trait.traitKey);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
89
|
+
finally {
|
|
90
|
+
try {
|
|
91
|
+
if (traits_1_1 && !traits_1_1.done && (_b = traits_1.return)) _b.call(traits_1);
|
|
92
|
+
}
|
|
93
|
+
finally { if (e_2) throw e_2.error; }
|
|
94
|
+
}
|
|
95
|
+
this.identityTraits = [];
|
|
96
|
+
try {
|
|
97
|
+
for (var _f = __values(existingTraits.entries()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
98
|
+
var _h = __read(_g.value, 2), k = _h[0], v = _h[1];
|
|
99
|
+
this.identityTraits.push(v);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
103
|
+
finally {
|
|
104
|
+
try {
|
|
105
|
+
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
106
|
+
}
|
|
107
|
+
finally { if (e_3) throw e_3.error; }
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return IdentityModel;
|
|
111
|
+
}());
|
|
112
|
+
exports.IdentityModel = IdentityModel;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraitModel = void 0;
|
|
4
|
+
var TraitModel = /** @class */ (function () {
|
|
5
|
+
function TraitModel(key, value) {
|
|
6
|
+
this.traitKey = key;
|
|
7
|
+
this.traitValue = value;
|
|
8
|
+
}
|
|
9
|
+
return TraitModel;
|
|
10
|
+
}());
|
|
11
|
+
exports.TraitModel = TraitModel;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.buildIdentityModel = exports.buildTraitModel = void 0;
|
|
29
|
+
var util_1 = require("../features/util");
|
|
30
|
+
var collections_1 = require("../utils/collections");
|
|
31
|
+
var models_1 = require("./models");
|
|
32
|
+
var models_2 = require("./traits/models");
|
|
33
|
+
function buildTraitModel(traitJSON) {
|
|
34
|
+
return new models_2.TraitModel(traitJSON.trait_key, traitJSON.trait_value);
|
|
35
|
+
}
|
|
36
|
+
exports.buildTraitModel = buildTraitModel;
|
|
37
|
+
function buildIdentityModel(identityJSON) {
|
|
38
|
+
var featureList = identityJSON.identity_features
|
|
39
|
+
? new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityJSON.identity_features.map(function (f) { return (0, util_1.buildFeatureStateModel)(f); })), false)))() : [];
|
|
40
|
+
var model = new models_1.IdentityModel(identityJSON.created_date, identityJSON.identity_traits
|
|
41
|
+
? identityJSON.identity_traits.map(function (trait) { return buildTraitModel(trait); })
|
|
42
|
+
: [], featureList, identityJSON.environment_api_key, identityJSON.identifier, identityJSON.identity_uuid);
|
|
43
|
+
model.djangoID = identityJSON.django_id;
|
|
44
|
+
return model;
|
|
45
|
+
}
|
|
46
|
+
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[];
|