forked from Flagsmith/flagsmith-nodejs-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
35 lines (32 loc) · 1.21 KB
/
util.ts
File metadata and controls
35 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { buildFeatureStateModel } from '../features/util.js';
import { buildIdentityModel } from '../identities/util.js';
import { buildProjectModel } from '../projects/util.js';
import { EnvironmentAPIKeyModel, EnvironmentModel } from './models.js';
export function buildEnvironmentModel(environmentJSON: any) {
const project = buildProjectModel(environmentJSON.project);
const featureStates = environmentJSON.feature_states.map((fs: any) =>
buildFeatureStateModel(fs)
);
const environmentModel = new EnvironmentModel(
environmentJSON.id,
environmentJSON.api_key,
project
);
environmentModel.featureStates = featureStates;
if (!!environmentJSON.identity_overrides) {
environmentModel.identityOverrides = environmentJSON.identity_overrides.map(
(identityData: any) => buildIdentityModel(identityData)
);
}
return environmentModel;
}
export function buildEnvironmentAPIKeyModel(apiKeyJSON: any): EnvironmentAPIKeyModel {
const model = new EnvironmentAPIKeyModel(
apiKeyJSON.id,
apiKeyJSON.key,
Date.parse(apiKeyJSON.created_at),
apiKeyJSON.name,
apiKeyJSON.client_api_key
);
return model;
}