({
attributes,
clientKey,
feature,
trackingCallback,
}: GetServerFeatureValueOptions<T>)
| 16 | }; |
| 17 | |
| 18 | export const getServerFeatureValue = async <T extends JSONValue>({ |
| 19 | attributes, |
| 20 | clientKey, |
| 21 | feature, |
| 22 | trackingCallback, |
| 23 | }: GetServerFeatureValueOptions<T>): Promise<T> => { |
| 24 | const { defaultValue, id } = feature; |
| 25 | |
| 26 | if (!clientKey) { |
| 27 | return defaultValue; |
| 28 | } |
| 29 | |
| 30 | const growthbook = new GrowthBook({ |
| 31 | apiHost: process.env.GROWTHBOOK_API_HOST ?? DEFAULT_API_HOST, |
| 32 | attributes, |
| 33 | clientKey, |
| 34 | trackingCallback, |
| 35 | }); |
| 36 | |
| 37 | try { |
| 38 | await growthbook.loadFeatures({ timeout: DEFAULT_TIMEOUT }); |
| 39 | return growthbook.getFeatureValue(id, defaultValue) as T; |
| 40 | } catch { |
| 41 | return defaultValue; |
| 42 | } finally { |
| 43 | growthbook.destroy(); |
| 44 | } |
| 45 | }; |
no outgoing calls
no test coverage detected