-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.d.ts
139 lines (119 loc) · 3.67 KB
/
index.d.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
export interface IBulletTrainFeature {
enabled: boolean
value?: string|number|boolean
}
export interface IFlags {
[key: string]: IBulletTrainFeature
}
export interface ITraits {
[key: string]: string
}
export interface IUserIdentity {
flags: IBulletTrainFeature
traits: ITraits
}
export interface IRetrieveInfo {
isFromServer: boolean
flagsChanged: boolean
traitsChanged: boolean
}
export interface IState {
api: string
environmentID: string
flags?: IFlags
identity?: string
traits: ITraits
}
declare class IFlagsmith {
/**
* Initialise the sdk against a particular environment
*/
init:(config: {
environmentID: string // your Bullet Train environment id
api?: string // the api you wish to use, important if self hosting
headers?: object // pass custom headers for flagsmith api calls
AsyncStorage?: any // an AsyncStorage implementation
cacheFlags?: boolean // whether to local storage flags, needs AsyncStorage defined
preventFetch?: boolean // whether to prevent fetching flags on init
enableAnalytics?: boolean // Enable sending flag analytics for getValue and hasFeature evaluations.
enableLogs?: boolean // whether to enable logs
onChange?: (previousFlags:IFlags, params:IRetrieveInfo)=> void // triggered when the flags are retrieved
state?: IState // set a predefined state, useful for isomorphic applications
onError?: (res:{message:string}) => void // triggered if there was an api error
defaultFlags?: IFlags //
}) => Promise<void>
/**
* Trigger a manual fetch of the environment features
*/
getFlags:()=> Promise<IFlags>
/**
* Returns the current flags
*/
getAllFlags:()=> IFlags
/**
* Identify user, triggers a call to get flags if flagsmith.init has been called
*/
identify:(userId:string, traits?: Record<string, string|number|boolean>,) => Promise<IFlags|undefined>
/**
* Retrieves the current state of flagsmith
*/
getState:()=> IState
/**
* Clears the identity, triggers a call to getFlags
*/
logout:()=> Promise<IFlags>
/**
* Polls the flagsmith API, specify interval in ms
*/
startListening:(interval?:number)=> void
/**
* Stops polling
*/
stopListening:()=> void
/**
* Get the whether a flag is enabled e.g. flagsmith.hasFeature("powerUserFeature")
*/
hasFeature:(key: string)=> boolean
/**
* Get the value of a particular remote config e.g. flagsmith.getValue("font_size")
*/
getValue:(key: string) => string|number|boolean
/**
* Get the value of a particular trait for the identified user
*/
getTrait:(key: string) => string|number|boolean
/**
* Set a specific trait for a given user id, triggers a call to get flags
*/
setTrait:(
key: string,
value: string|number|boolean
)=> Promise<IFlags>
/**
* Set a key value set of traits for a given user, triggers a call to get flags
*/
setTraits:(
traits: Record<string, string|number|boolean>,
)=> Promise<IFlags>
/**
* Increments the value of a numeric trait by a given amount (can be negative number)
*/
incrementTrait:(
key:string,
incrementBy:number
)=> Promise<IFlags>
/**
* The stored identity of the user
*/
identity?:string
}
declare module 'flagsmith' {
// @ts-ignore
export default new IFlagsmith()
export function createFlagsmithInstance (): IFlagsmith
}
// @ts-ignore
declare module 'flagsmith/isomorphic' {
// @ts-ignore
export default new IFlagsmith()
}