-
Notifications
You must be signed in to change notification settings - Fork 391
/
Copy pathfeature-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
*/
export const isFeatureFlagEnabled = (
flagName: string,
siteInfo: { feature_flags?: Record<string, string | boolean> | undefined },
): 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, string | boolean> | undefined
}): 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),
netlify_build_frameworks_api: true,
project_ceruledge_ui: true,
})
export type FeatureFlags = Record<string, boolean | string | number>