-
Notifications
You must be signed in to change notification settings - Fork 366
/
feature-flags.ts
28 lines (26 loc) · 1.2 KB
/
feature-flags.ts
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
/**
* Allows us to check if a feature flag is enabled for a site.
* Due to versioning of the cli, and the desire to remove flags from
* our feature flag service when they should always evaluate to true,
* we can't just look for the presense of {featureFlagName: true}, as
* the absense of a flag should also evaluate to the flag being enabled.
* Instead, we return that the feature flag is enabled if it isn't
* specifically set to false in the response
* @param {*} siteInfo
*
* @returns {boolean}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'flagName' implicitly has an 'any' type.
export const isFeatureFlagEnabled = (flagName: string, siteInfo): boolean =>
Boolean(siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false)
/**
* Retrieves all Feature flags from the siteInfo
*/
export const getFeatureFlagsFromSiteInfo = (siteInfo: {
feature_flags?: Record<string, boolean | string | number>
}): FeatureFlags => ({
...(siteInfo.feature_flags || {}),
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
})
export type FeatureFlags = Record<string, boolean | string | number>