Skip to content

Commit 759d038

Browse files
committed
bootstrap to set initial config then, fire-and-forget initialization
1 parent 31c3db9 commit 759d038

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/client/eppo-client.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.stor
2222
import {
2323
ConfigurationWireV1,
2424
IConfigurationWire,
25+
inflateResponse,
2526
IPrecomputedConfiguration,
2627
PrecomputedConfiguration,
2728
} from '../configuration-wire/configuration-wire-types';
@@ -325,7 +326,32 @@ export default class EppoClient {
325326
);
326327
}
327328

329+
bootstrap(configuration: IConfigurationWire) {
330+
if (!configuration.config) {
331+
throw new Error('Flag configuration not provided');
332+
}
333+
const flagConfigResponse = inflateResponse(configuration.config.response);
334+
const banditParamResponse = configuration.bandits
335+
? inflateResponse(configuration.bandits.response)
336+
: undefined;
337+
338+
this.configurationManager.hydrateConfigurationStoresFromUfc(
339+
flagConfigResponse,
340+
banditParamResponse,
341+
);
342+
343+
// Still initialize the client in case polling is needed.
344+
this.inititalize();
345+
}
346+
347+
/**
348+
* @deprecated use `initialize` instead.
349+
*/
328350
async fetchFlagConfigurations() {
351+
return this.inititalize();
352+
}
353+
354+
async inititalize() {
329355
if (!this.configurationRequestParameters) {
330356
throw new Error(
331357
'Eppo SDK unable to fetch flag configurations without configuration request parameters',

0 commit comments

Comments
 (0)