-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathfeature-flags.ts
More file actions
120 lines (105 loc) · 3.45 KB
/
feature-flags.ts
File metadata and controls
120 lines (105 loc) · 3.45 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Feature flag types
*/
import type { JsonType } from './common'
export type FeatureFlagsCallback = (
flags: string[],
variants: Record<string, string | boolean>,
context?: {
errorsLoading?: boolean
}
) => void
export type FeatureFlagDetail = {
key: string
enabled: boolean
// Only used when overriding a flag payload.
original_enabled?: boolean | undefined
variant: string | undefined
// Only used when overriding a flag payload.
original_variant?: string | undefined
reason: EvaluationReason | undefined
metadata: FeatureFlagMetadata | undefined
failed?: boolean
}
export type FeatureFlagMetadata = {
id: number
version: number | undefined
description: string | undefined
payload: JsonType | undefined
// Only used when overriding a flag payload.
original_payload?: JsonType | undefined
}
export type EvaluationReason = {
code: string
condition_index: number | undefined
description: string | undefined
}
export type RemoteConfigFeatureFlagCallback = (payload: JsonType) => void
// Sync this with the backend's EarlyAccessFeatureSerializer!
/** A feature that isn't publicly available yet.*/
export interface EarlyAccessFeature {
name: string
description: string
stage: 'concept' | 'alpha' | 'beta'
documentationUrl: string | null
payload: JsonType
flagKey: string | null
}
export type EarlyAccessFeatureStage = 'concept' | 'alpha' | 'beta' | 'general-availability'
export type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void
/**
* Result of evaluating a feature flag, including both the flag value and its payload.
*/
export type FeatureFlagResult = {
/** The key of the feature flag */
readonly key: string
/** Whether the feature flag is enabled (truthy value) */
readonly enabled: boolean
/** The variant key if this is a multivariate flag, undefined for boolean flags */
readonly variant: string | undefined
/** The JSON payload associated with this flag, if any */
readonly payload: JsonType | undefined
}
export interface EarlyAccessFeatureResponse {
earlyAccessFeatures: EarlyAccessFeature[]
}
export type FeatureFlagOverrides = {
[flagName: string]: string | boolean
}
export type FeatureFlagPayloadOverrides = {
[flagName: string]: JsonType
}
export type FeatureFlagOverrideOptions = {
flags?: boolean | string[] | FeatureFlagOverrides
payloads?: FeatureFlagPayloadOverrides
suppressWarning?: boolean
}
/**
* Options for feature flag lookup methods (getFeatureFlag, isFeatureEnabled, getFeatureFlagResult).
*/
export type FeatureFlagOptions = {
/**
* Whether to send a $feature_flag_called event. Defaults to true.
*/
send_event?: boolean
/**
* If true, only return values loaded from the server, not cached localStorage values.
* Returns undefined if flags haven't been loaded from the server yet.
* Defaults to false.
*/
fresh?: boolean
}
/**
* Options for overriding feature flags on the client-side.
*
* Can be:
* - `false` to clear all overrides
* - `string[]` to enable a list of flags
* - `FeatureFlagOverrides` to set variants directly
* - `FeatureFlagOverrideOptions` for granular control over flags and payloads
*/
export type OverrideFeatureFlagsOptions =
| boolean // clear all overrides
| string[] // enable list of flags
| FeatureFlagOverrides // set variants directly
| FeatureFlagOverrideOptions