1
1
import { IConfigurationStore } from './configuration-store/configuration-store' ;
2
+ import { hydrateConfigurationStore } from './configuration-store/configuration-store-utils' ;
2
3
import { IHttpClient } from './http-client' ;
3
- import {
4
- BanditVariation ,
5
- BanditParameters ,
6
- Flag ,
7
- Environment ,
8
- PrecomputedFlag ,
9
- } from './interfaces' ;
10
-
11
- type Entry = Flag | BanditVariation [ ] | BanditParameters | PrecomputedFlag ;
4
+ import { BanditVariation , BanditParameters , Flag } from './interfaces' ;
12
5
13
6
// Requests AND stores flag configurations
14
7
export default class ConfigurationRequestor {
@@ -18,7 +11,6 @@ export default class ConfigurationRequestor {
18
11
private readonly banditVariationConfigurationStore : IConfigurationStore <
19
12
BanditVariation [ ]
20
13
> | null ,
21
- private readonly precomputedFlagStore : IConfigurationStore < PrecomputedFlag > ,
22
14
private readonly banditModelConfigurationStore : IConfigurationStore < BanditParameters > | null ,
23
15
) { }
24
16
@@ -28,7 +20,7 @@ export default class ConfigurationRequestor {
28
20
return ;
29
21
}
30
22
31
- await this . hydrateConfigurationStore ( this . flagConfigurationStore , {
23
+ await hydrateConfigurationStore ( this . flagConfigurationStore , {
32
24
entries : configResponse . flags ,
33
25
environment : configResponse . environment ,
34
26
createdAt : configResponse . createdAt ,
@@ -42,7 +34,7 @@ export default class ConfigurationRequestor {
42
34
// Map bandit flag associations by flag key for quick lookup (instead of bandit key as provided by the UFC)
43
35
const banditVariations = this . indexBanditVariationsByFlagKey ( configResponse . bandits ) ;
44
36
45
- await this . hydrateConfigurationStore ( this . banditVariationConfigurationStore , {
37
+ await hydrateConfigurationStore ( this . banditVariationConfigurationStore , {
46
38
entries : banditVariations ,
47
39
environment : configResponse . environment ,
48
40
createdAt : configResponse . createdAt ,
@@ -55,7 +47,7 @@ export default class ConfigurationRequestor {
55
47
throw new Error ( 'Bandit parameters fetched but no bandit configuration store provided' ) ;
56
48
}
57
49
58
- await this . hydrateConfigurationStore ( this . banditModelConfigurationStore , {
50
+ await hydrateConfigurationStore ( this . banditModelConfigurationStore , {
59
51
entries : banditResponse . bandits ,
60
52
environment : configResponse . environment ,
61
53
createdAt : configResponse . createdAt ,
@@ -64,24 +56,6 @@ export default class ConfigurationRequestor {
64
56
}
65
57
}
66
58
67
- private async hydrateConfigurationStore < T extends Entry > (
68
- configurationStore : IConfigurationStore < T > | null ,
69
- response : {
70
- entries : Record < string , T > ;
71
- environment : Environment ;
72
- createdAt : string ;
73
- } ,
74
- ) : Promise < void > {
75
- if ( configurationStore ) {
76
- const didUpdate = await configurationStore . setEntries ( response . entries ) ;
77
- if ( didUpdate ) {
78
- configurationStore . setEnvironment ( response . environment ) ;
79
- configurationStore . setConfigFetchedAt ( new Date ( ) . toISOString ( ) ) ;
80
- configurationStore . setConfigPublishedAt ( response . createdAt ) ;
81
- }
82
- }
83
- }
84
-
85
59
private indexBanditVariationsByFlagKey (
86
60
banditVariationsByBanditKey : Record < string , BanditVariation [ ] > ,
87
61
) : Record < string , BanditVariation [ ] > {
@@ -98,17 +72,4 @@ export default class ConfigurationRequestor {
98
72
} ) ;
99
73
return banditVariationsByFlagKey ;
100
74
}
101
-
102
- async fetchAndStorePrecomputedFlags ( ) : Promise < void > {
103
- const precomputedResponse = await this . httpClient . getPrecomputedFlags ( ) ;
104
- if ( ! precomputedResponse ?. flags ) {
105
- return ;
106
- }
107
-
108
- await this . hydrateConfigurationStore ( this . precomputedFlagStore , {
109
- entries : precomputedResponse . flags ,
110
- environment : precomputedResponse . environment ,
111
- createdAt : precomputedResponse . createdAt ,
112
- } ) ;
113
- }
114
75
}
0 commit comments