11import {
22 CheckEvent ,
3+ FallbackFeatureOverride ,
34 FeaturesClient ,
4- FeaturesOptions ,
55 RawFeatures ,
66} from "./feature/features" ;
77import {
@@ -185,7 +185,7 @@ export type FeatureDefinitions = Readonly<Array<string>>;
185185/**
186186 * BucketClient initialization options.
187187 */
188- export interface InitOptions {
188+ export type InitOptions = {
189189 /**
190190 * Publishable key for authentication
191191 */
@@ -218,12 +218,6 @@ export interface InitOptions {
218218 */
219219 logger ?: Logger ;
220220
221- /**
222- * @deprecated
223- * Use `apiBaseUrl` instead.
224- */
225- host ?: string ;
226-
227221 /**
228222 * Base URL of Bucket servers. You can override this to use your mocked server.
229223 */
@@ -235,10 +229,32 @@ export interface InitOptions {
235229 appBaseUrl ?: string ;
236230
237231 /**
238- * @deprecated
239- * Use `sseBaseUrl` instead.
232+ * Feature keys for which `isEnabled` should fallback to true
233+ * if SDK fails to fetch features from Bucket servers. If a record
234+ * is supplied instead of array, the values of each key represent the
235+ * configuration values and `isEnabled` is assume `true`.
236+ */
237+ fallbackFeatures ?: string [ ] | Record < string , FallbackFeatureOverride > ;
238+
239+ /**
240+ * Timeout in milliseconds when fetching features
241+ */
242+ timeoutMs ?: number ;
243+
244+ /**
245+ * If set to true stale features will be returned while refetching features
246+ */
247+ staleWhileRevalidate ?: boolean ;
248+
249+ /**
250+ * If set, features will be cached between page loads for this duration
251+ */
252+ expireTimeMs ?: number ;
253+
254+ /**
255+ * Stale features will be returned if staleWhileRevalidate is true if no new features can be fetched
240256 */
241- sseHost ?: string ;
257+ staleTimeMs ?: number ;
242258
243259 /**
244260 * Base URL of Bucket servers for SSE connections used by AutoFeedback.
@@ -250,11 +266,6 @@ export interface InitOptions {
250266 */
251267 feedback ?: FeedbackOptions ;
252268
253- /**
254- * Feature flag specific configuration
255- */
256- features ?: FeaturesOptions ;
257-
258269 /**
259270 * Version of the SDK
260271 */
@@ -266,17 +277,15 @@ export interface InitOptions {
266277 enableTracking ?: boolean ;
267278
268279 /**
269- * Toolbar configuration (alpha)
270- * @ignore
280+ * Toolbar configuration
271281 */
272282 toolbar ?: ToolbarOptions ;
273283
274284 /**
275- * Local-first definition of features (alpha)
276- * @ignore
285+ * Local-first definition of features
277286 */
278- featureList ?: FeatureDefinitions ;
279- }
287+ features ?: FeatureDefinitions ;
288+ } ;
280289
281290const defaultConfig : Config = {
282291 apiBaseUrl : API_BASE_URL ,
@@ -335,7 +344,7 @@ function shouldShowToolbar(opts: InitOptions) {
335344 if ( typeof toolbarOpts ?. show === "boolean" ) return toolbarOpts . show ;
336345
337346 return (
338- opts . featureList !== undefined && window ?. location ?. hostname === "localhost"
347+ opts . features !== undefined && window ?. location ?. hostname === "localhost"
339348 ) ;
340349}
341350
@@ -369,9 +378,9 @@ export class BucketClient {
369378 } ;
370379
371380 this . config = {
372- apiBaseUrl : opts ?. apiBaseUrl ?? opts ?. host ?? defaultConfig . apiBaseUrl ,
373- appBaseUrl : opts ?. appBaseUrl ?? opts ?. host ?? defaultConfig . appBaseUrl ,
374- sseBaseUrl : opts ?. sseBaseUrl ?? opts ?. sseHost ?? defaultConfig . sseBaseUrl ,
381+ apiBaseUrl : opts ?. apiBaseUrl ?? defaultConfig . apiBaseUrl ,
382+ appBaseUrl : opts ?. appBaseUrl ?? defaultConfig . appBaseUrl ,
383+ sseBaseUrl : opts ?. sseBaseUrl ?? defaultConfig . sseBaseUrl ,
375384 enableTracking : opts ?. enableTracking ?? defaultConfig . enableTracking ,
376385 } ;
377386
@@ -395,9 +404,13 @@ export class BucketClient {
395404 company : this . context . company ,
396405 other : this . context . otherContext ,
397406 } ,
398- opts ?. featureList || [ ] ,
399407 this . logger ,
400- opts ?. features ,
408+ {
409+ expireTimeMs : opts . expireTimeMs ,
410+ staleTimeMs : opts . staleTimeMs ,
411+ fallbackFeatures : opts . fallbackFeatures ,
412+ timeoutMs : opts . timeoutMs ,
413+ } ,
401414 ) ;
402415
403416 if (
0 commit comments