@featbit/js-client-sdk 3.0.13 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +301 -301
  3. package/dist/esm/FbClientCore.d.ts +6 -5
  4. package/dist/esm/FbClientCore.d.ts.map +1 -1
  5. package/dist/esm/FbClientCore.js +27 -4
  6. package/dist/esm/FbClientCore.js.map +1 -1
  7. package/dist/esm/IFbClientCore.d.ts +8 -7
  8. package/dist/esm/IFbClientCore.d.ts.map +1 -1
  9. package/dist/esm/version.d.ts +1 -1
  10. package/dist/esm/version.d.ts.map +1 -1
  11. package/dist/esm/version.js +1 -1
  12. package/dist/esm/version.js.map +1 -1
  13. package/dist/umd/featbit-js-client-sdk-4.0.0.js +2 -0
  14. package/dist/umd/featbit-js-client-sdk-4.0.0.js.map +1 -0
  15. package/dist/umd/featbit-js-client-sdk.js +1 -1
  16. package/dist/umd/featbit-js-client-sdk.js.map +1 -1
  17. package/package.json +46 -46
  18. package/src/Configuration.ts +232 -232
  19. package/src/Context.ts +61 -61
  20. package/src/FbClientBuilder.ts +167 -167
  21. package/src/FbClientCore.ts +428 -405
  22. package/src/IContextProperty.ts +3 -3
  23. package/src/IDataKind.ts +11 -11
  24. package/src/IFbClient.ts +29 -29
  25. package/src/IFbClientCore.ts +291 -290
  26. package/src/IVersionedData.ts +18 -18
  27. package/src/bootstrap/IBootstrapProvider.ts +4 -4
  28. package/src/bootstrap/JsonBootstrapProvider.ts +34 -34
  29. package/src/bootstrap/NullBootstrapProvider.ts +20 -20
  30. package/src/bootstrap/index.ts +2 -2
  31. package/src/constants.ts +1 -1
  32. package/src/data-sources/DataSourceUpdates.ts +116 -116
  33. package/src/data-sources/createStreamListeners.ts +67 -67
  34. package/src/data-sources/index.ts +1 -1
  35. package/src/data-sync/DataSyncMode.ts +3 -3
  36. package/src/data-sync/IDataSynchronizer.ts +15 -15
  37. package/src/data-sync/IRequestor.ts +10 -10
  38. package/src/data-sync/NullDataSynchronizer.ts +14 -14
  39. package/src/data-sync/PollingDataSynchronizer.ts +125 -125
  40. package/src/data-sync/Requestor.ts +61 -61
  41. package/src/data-sync/WebSocketDataSynchronizer.ts +77 -77
  42. package/src/data-sync/index.ts +8 -8
  43. package/src/data-sync/types.ts +19 -19
  44. package/src/data-sync/utils.ts +31 -31
  45. package/src/errors.ts +47 -47
  46. package/src/evaluation/EvalResult.ts +35 -35
  47. package/src/evaluation/Evaluator.ts +26 -26
  48. package/src/evaluation/IEvalDetail.ts +23 -23
  49. package/src/evaluation/ReasonKinds.ts +9 -9
  50. package/src/evaluation/data/IFlag.ts +29 -29
  51. package/src/evaluation/index.ts +4 -4
  52. package/src/events/DefaultEventProcessor.ts +83 -83
  53. package/src/events/DefaultEventQueue.ts +49 -49
  54. package/src/events/DefaultEventSender.ts +73 -73
  55. package/src/events/DefaultEventSerializer.ts +11 -11
  56. package/src/events/EventDispatcher.ts +127 -127
  57. package/src/events/EventSerializer.ts +4 -4
  58. package/src/events/IEventProcessor.ts +8 -8
  59. package/src/events/IEventQueue.ts +16 -16
  60. package/src/events/IEventSender.ts +13 -13
  61. package/src/events/NullEventProcessor.ts +15 -15
  62. package/src/events/event.ts +129 -129
  63. package/src/events/index.ts +11 -11
  64. package/src/index.ts +21 -21
  65. package/src/integrations/TestLogger.ts +24 -24
  66. package/src/integrations/index.ts +1 -1
  67. package/src/integrations/test_data/FlagBuilder.ts +59 -59
  68. package/src/integrations/test_data/TestData.ts +57 -57
  69. package/src/integrations/test_data/TestDataSynchronizer.ts +49 -49
  70. package/src/integrations/test_data/index.ts +4 -4
  71. package/src/logging/BasicLogger.ts +108 -108
  72. package/src/logging/IBasicLoggerOptions.ts +46 -46
  73. package/src/logging/ILogger.ts +49 -49
  74. package/src/logging/LogLevel.ts +8 -8
  75. package/src/logging/SafeLogger.ts +69 -69
  76. package/src/logging/format.ts +154 -154
  77. package/src/logging/index.ts +5 -5
  78. package/src/options/ClientContext.ts +39 -39
  79. package/src/options/IClientContext.ts +53 -53
  80. package/src/options/IOptions.ts +123 -123
  81. package/src/options/IUser.ts +6 -6
  82. package/src/options/IValidatedOptions.ts +29 -29
  83. package/src/options/OptionMessages.ts +35 -35
  84. package/src/options/UserBuilder.ts +35 -35
  85. package/src/options/Validators.ts +300 -300
  86. package/src/options/index.ts +7 -7
  87. package/src/platform/IInfo.ts +102 -102
  88. package/src/platform/IPlatform.ts +20 -20
  89. package/src/platform/IStore.ts +112 -112
  90. package/src/platform/IWebSocket.ts +22 -22
  91. package/src/platform/browser/BrowserInfo.ts +24 -24
  92. package/src/platform/browser/BrowserPlatform.ts +19 -19
  93. package/src/platform/browser/BrowserRequests.ts +6 -6
  94. package/src/platform/browser/BrowserWebSocket.ts +147 -147
  95. package/src/platform/browser/FbClient.ts +65 -65
  96. package/src/platform/browser/LocalStorageStore.ts +59 -59
  97. package/src/platform/index.ts +11 -11
  98. package/src/platform/requests.ts +76 -76
  99. package/src/store/BaseStore.ts +125 -125
  100. package/src/store/DataKinds.ts +6 -6
  101. package/src/store/IDataSourceUpdates.ts +68 -68
  102. package/src/store/InMemoryStore.ts +36 -36
  103. package/src/store/index.ts +5 -5
  104. package/src/store/serialization.ts +52 -52
  105. package/src/store/store.ts +37 -37
  106. package/src/utils/Emits.ts +75 -75
  107. package/src/utils/EventEmitter.ts +128 -128
  108. package/src/utils/IEventEmitter.ts +14 -14
  109. package/src/utils/Regex.ts +21 -21
  110. package/src/utils/ValueConverters.ts +55 -55
  111. package/src/utils/canonicalizeUri.ts +3 -3
  112. package/src/utils/debounce.ts +33 -33
  113. package/src/utils/http.ts +40 -40
  114. package/src/utils/index.ts +5 -5
  115. package/src/utils/isNullOrUndefined.ts +2 -2
  116. package/src/utils/serializeUser.ts +27 -27
  117. package/src/utils/sleep.ts +5 -5
  118. package/src/version.ts +1 -1
  119. package/dist/umd/featbit-js-client-sdk-3.0.13.js +0 -2
  120. package/dist/umd/featbit-js-client-sdk-3.0.13.js.map +0 -1
@@ -1,291 +1,292 @@
1
- import { IEvalDetail } from "./evaluation/IEvalDetail";
2
- import { IConvertResult } from "./utils/ValueConverters";
3
- import { IUser } from "./options";
4
-
5
- /**
6
- * The FeatBit SDK client object.
7
- *
8
- * Create this object with {@link FbClientBuilder}. Applications should configure the client at startup time
9
- * and continue to use it throughout the lifetime of the application, rather than creating instances
10
- * on the fly.
11
- *
12
- */
13
- export interface IFbClientCore {
14
- /**
15
- * Set the current user of the client.
16
- *
17
- * @param user
18
- * The current user. The actual type of this parameter is
19
- * {@link IUser}.
20
- */
21
- identify(user: IUser): void;
22
-
23
- /**
24
- * Indicates whether the client is ready to be used.
25
- *
26
- * @returns true if the client is ready to be used, false otherwise.
27
- */
28
- initialized(): boolean;
29
-
30
- /**
31
- * Wait until the client is initialized. The promise resolves when the client has finished initializing successfully.
32
- * If the client fails to initialize, the promise will be rejected.
33
- *
34
- * @returns A promise.
35
- */
36
- waitForInitialization(): Promise<IFbClientCore>;
37
-
38
- /**
39
- * Calculates the boolean value of a feature flag for a given user.
40
- *
41
- * If the flag variation does not have a boolean value, {@link defaultValue} is returned.
42
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
43
- * does not match any existing flag), {@link defaultValue} is returned.
44
- *
45
- * @param key
46
- * The unique key of the feature flag.
47
- * @param defaultValue
48
- * The default value to return if the flag cannot be evaluated.
49
- *
50
- * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
51
- */
52
- boolVariation(
53
- key: string,
54
- defaultValue: boolean
55
- ): boolean;
56
-
57
- /**
58
- * Calculates the boolean value of a feature flag for a given user, and returns an object that
59
- * describes the way the value was determined.
60
- *
61
- * If the flag variation does not have a boolean value, {@link defaultValue} is returned.
62
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
63
- * does not match any existing flag), {@link defaultValue} is returned.
64
- *
65
- * @param key
66
- * The unique key of the feature flag.
67
- * @param defaultValue
68
- * The default value to return if the flag cannot be evaluated.
69
- *
70
- * @returns {@link IEvalDetail} object describing the way the value was determined.
71
- */
72
- boolVariationDetail(
73
- key: string,
74
- defaultValue: boolean
75
- ): IEvalDetail<boolean>;
76
-
77
- /**
78
- * Calculates the number value of a feature flag for a given user.
79
- *
80
- * If the flag variation does not have a number value, {@link defaultValue} is returned.
81
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
82
- * does not match any existing flag), {@link defaultValue} is returned.
83
- *
84
- * @param key
85
- * The unique key of the feature flag.
86
- * @param defaultValue
87
- * The default value to return if the flag cannot be evaluated.
88
- *
89
- * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
90
- */
91
- numberVariation(
92
- key: string,
93
- defaultValue: number
94
- ): number;
95
-
96
- /**
97
- * Calculates the number value of a feature flag for a given user, and returns an object that
98
- * describes the way the value was determined.
99
- *
100
- * If the flag variation does not have a number value, {@link defaultValue} is returned.
101
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
102
- * does not match any existing flag), {@link defaultValue} is returned.
103
- *
104
- * @param key
105
- * The unique key of the feature flag.
106
- * @param defaultValue
107
- * The default value to return if the flag cannot be evaluated.
108
- *
109
- * @returns {@link IEvalDetail} object describing the way the value was determined.
110
- */
111
- numberVariationDetail(
112
- key: string,
113
- defaultValue: number
114
- ): IEvalDetail<number>;
115
-
116
- /**
117
- * Calculates the string value of a feature flag for a given user.
118
- *
119
- * If the flag variation does not have a string value, {@link defaultValue} is returned.
120
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
121
- * does not match any existing flag), {@link defaultValue} is returned.
122
- *
123
- * @param key
124
- * The unique key of the feature flag.
125
- * @param defaultValue
126
- * The default value to return if the flag cannot be evaluated.
127
- *
128
- * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
129
- */
130
- stringVariation(
131
- key: string,
132
- defaultValue: string
133
- ): string;
134
-
135
- /**
136
- * Calculates the string value of a feature flag for a given user, and returns an object that
137
- * describes the way the value was determined.
138
- *
139
- * If the flag variation does not have a string value, {@link defaultValue} is returned.
140
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
141
- * does not match any existing flag), {@link defaultValue} is returned.
142
- *
143
- * @param key
144
- * The unique key of the feature flag.
145
- * @param defaultValue
146
- * The default value to return if the flag cannot be evaluated.
147
- *
148
- * @returns {@link IEvalDetail} object describing the way the value was determined.
149
- */
150
- stringVariationDetail(
151
- key: string,
152
- defaultValue: string
153
- ): IEvalDetail<string>;
154
-
155
- /**
156
- * Calculates the JSON value of a feature flag for a given user.
157
- *
158
- * If the flag variation does not have a JSON value, {@link defaultValue} is returned.
159
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
160
- * does not match any existing flag), {@link defaultValue} is returned.
161
- *
162
- * @param key
163
- * The unique key of the feature flag.
164
- * @param defaultValue
165
- * The default value to return if the flag cannot be evaluated.
166
- *
167
- * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
168
- */
169
- jsonVariation(
170
- key: string,
171
- defaultValue: any
172
- ): any;
173
-
174
- /**
175
- * Calculates the JSON value of a feature flag for a given user, and returns an object that
176
- * describes the way the value was determined.
177
- *
178
- * If the flag variation does not have a JSON value, {@link defaultValue} is returned.
179
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
180
- * does not match any existing flag), {@link defaultValue} is returned.
181
- *
182
- * @param key
183
- * The unique key of the feature flag.
184
- * @param defaultValue
185
- * The default value to return if the flag cannot be evaluated.
186
- *
187
- * @returns {@link IEvalDetail} object describing the way the value was determined.
188
- */
189
- jsonVariationDetail(
190
- key: string,
191
- defaultValue: any
192
- ): IEvalDetail<any>;
193
-
194
- /**
195
- * Calculates the string value of a feature flag for a given user.
196
- *
197
- * If the flag variation does not have a string value, {@link defaultValue} is returned.
198
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
199
- * does not match any existing flag), {@link defaultValue} is returned.
200
- *
201
- * @param key
202
- * The unique key of the feature flag.
203
- * @param defaultValue
204
- * The default value to return if the flag cannot be evaluated.
205
- *
206
- * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
207
- */
208
- variation(
209
- key: string,
210
- defaultValue: string
211
- ): string;
212
-
213
- /**
214
- * Calculates the string value of a feature flag for a given user, and returns an object that
215
- * describes the way the value was determined.
216
- *
217
- * If the flag variation does not have a string value, {@link defaultValue} is returned.
218
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
219
- * does not match any existing flag), {@link defaultValue} is returned.
220
- *
221
- * @param key
222
- * The unique key of the feature flag.
223
- * @param defaultValue
224
- * The default value to return if the flag cannot be evaluated.
225
- *
226
- * @returns {@link IEvalDetail} object describing the way the value was determined.
227
- */
228
- variationDetail(
229
- key: string,
230
- defaultValue: string
231
- ): IEvalDetail<string>;
232
-
233
- /**
234
- * This method is exposed only for testing purpose, please DO NOT USE IT
235
- *
236
- * Calculates the value of a feature flag for a given user, and returns a {@link IEvalDetail} object that
237
- * describes the way the value was determined.
238
- *
239
- * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
240
- * does not match any existing flag), {@link defaultValue} is returned.
241
- *
242
- * @param flagKey
243
- * The unique key of the feature flag.
244
- * @param defaultValue
245
- * The default value to return if the flag cannot be evaluated.
246
- * @param typeConverter
247
- * the function to convert result.
248
- *
249
- * @returns {@link IEvalDetail} object describing the way the value was determined.
250
- */
251
- evaluateCore<TValue>(
252
- flagKey: string,
253
- defaultValue: TValue,
254
- typeConverter: (value: string) => IConvertResult<TValue>
255
- ): IEvalDetail<TValue>;
256
-
257
- /**
258
- * Returns the variation with of all feature flags for a given user, and returns an object that
259
- * describes the way the value was determined for each flag.
260
- *
261
- * @returns A list of {@link IEvalDetail} objects describing the way the values were determined.
262
- */
263
- getAllVariations(): Promise<IEvalDetail<string>[]>;
264
-
265
- /**
266
- * Shuts down the client and releases any resources it is using.
267
- *
268
- * @returns A promise that resolves when the client has been shut down.
269
- */
270
- close(): Promise<void>;
271
-
272
- /**
273
- * Tracks that an application-defined event occurred, and provides an additional numeric value for custom metrics.
274
- *
275
- * @param eventName
276
- * the name of the event.
277
- * @param metricValue
278
- * a numeric value used by the FeatBit experimentation feature in custom numeric metrics, the default value is 1 if not provided.
279
- */
280
- track(eventName: string, metricValue?: number | undefined): void
281
-
282
- /**
283
- * Tells the client that all pending events (if any) should be delivered as soon as possible.
284
- *
285
- * @param callback
286
- * Will be called when the flush operation is complete. If the flush fails, the callback will be called with false.
287
- *
288
- * @returns A promise that resolves when the client has been shut down.
289
- */
290
- flush(callback?: (res: boolean) => void): Promise<boolean>;
1
+ import { IEvalDetail } from "./evaluation/IEvalDetail";
2
+ import { IConvertResult } from "./utils/ValueConverters";
3
+ import { IUser } from "./options";
4
+ import { FlagValue } from "./evaluation";
5
+
6
+ /**
7
+ * The FeatBit SDK client object.
8
+ *
9
+ * Create this object with {@link FbClientBuilder}. Applications should configure the client at startup time
10
+ * and continue to use it throughout the lifetime of the application, rather than creating instances
11
+ * on the fly.
12
+ *
13
+ */
14
+ export interface IFbClientCore {
15
+ /**
16
+ * Set the current user of the client.
17
+ *
18
+ * @param user
19
+ * The current user. The actual type of this parameter is
20
+ * {@link IUser}.
21
+ */
22
+ identify(user: IUser): Promise<void>;
23
+
24
+ /**
25
+ * Indicates whether the client is ready to be used.
26
+ *
27
+ * @returns true if the client is ready to be used, false otherwise.
28
+ */
29
+ initialized(): boolean;
30
+
31
+ /**
32
+ * Wait until the client is initialized. The promise resolves when the client has finished initializing successfully.
33
+ * If the client fails to initialize, the promise will be rejected.
34
+ *
35
+ * @returns A promise.
36
+ */
37
+ waitForInitialization(): Promise<IFbClientCore>;
38
+
39
+ /**
40
+ * Calculates the boolean value of a feature flag for a given user.
41
+ *
42
+ * If the flag variation does not have a boolean value, {@link defaultValue} is returned.
43
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
44
+ * does not match any existing flag), {@link defaultValue} is returned.
45
+ *
46
+ * @param key
47
+ * The unique key of the feature flag.
48
+ * @param defaultValue
49
+ * The default value to return if the flag cannot be evaluated.
50
+ *
51
+ * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
52
+ */
53
+ boolVariation(
54
+ key: string,
55
+ defaultValue: boolean
56
+ ): boolean;
57
+
58
+ /**
59
+ * Calculates the boolean value of a feature flag for a given user, and returns an object that
60
+ * describes the way the value was determined.
61
+ *
62
+ * If the flag variation does not have a boolean value, {@link defaultValue} is returned.
63
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
64
+ * does not match any existing flag), {@link defaultValue} is returned.
65
+ *
66
+ * @param key
67
+ * The unique key of the feature flag.
68
+ * @param defaultValue
69
+ * The default value to return if the flag cannot be evaluated.
70
+ *
71
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
72
+ */
73
+ boolVariationDetail(
74
+ key: string,
75
+ defaultValue: boolean
76
+ ): IEvalDetail<boolean>;
77
+
78
+ /**
79
+ * Calculates the number value of a feature flag for a given user.
80
+ *
81
+ * If the flag variation does not have a number value, {@link defaultValue} is returned.
82
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
83
+ * does not match any existing flag), {@link defaultValue} is returned.
84
+ *
85
+ * @param key
86
+ * The unique key of the feature flag.
87
+ * @param defaultValue
88
+ * The default value to return if the flag cannot be evaluated.
89
+ *
90
+ * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
91
+ */
92
+ numberVariation(
93
+ key: string,
94
+ defaultValue: number
95
+ ): number;
96
+
97
+ /**
98
+ * Calculates the number value of a feature flag for a given user, and returns an object that
99
+ * describes the way the value was determined.
100
+ *
101
+ * If the flag variation does not have a number value, {@link defaultValue} is returned.
102
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
103
+ * does not match any existing flag), {@link defaultValue} is returned.
104
+ *
105
+ * @param key
106
+ * The unique key of the feature flag.
107
+ * @param defaultValue
108
+ * The default value to return if the flag cannot be evaluated.
109
+ *
110
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
111
+ */
112
+ numberVariationDetail(
113
+ key: string,
114
+ defaultValue: number
115
+ ): IEvalDetail<number>;
116
+
117
+ /**
118
+ * Calculates the string value of a feature flag for a given user.
119
+ *
120
+ * If the flag variation does not have a string value, {@link defaultValue} is returned.
121
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
122
+ * does not match any existing flag), {@link defaultValue} is returned.
123
+ *
124
+ * @param key
125
+ * The unique key of the feature flag.
126
+ * @param defaultValue
127
+ * The default value to return if the flag cannot be evaluated.
128
+ *
129
+ * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
130
+ */
131
+ stringVariation(
132
+ key: string,
133
+ defaultValue: string
134
+ ): string;
135
+
136
+ /**
137
+ * Calculates the string value of a feature flag for a given user, and returns an object that
138
+ * describes the way the value was determined.
139
+ *
140
+ * If the flag variation does not have a string value, {@link defaultValue} is returned.
141
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
142
+ * does not match any existing flag), {@link defaultValue} is returned.
143
+ *
144
+ * @param key
145
+ * The unique key of the feature flag.
146
+ * @param defaultValue
147
+ * The default value to return if the flag cannot be evaluated.
148
+ *
149
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
150
+ */
151
+ stringVariationDetail(
152
+ key: string,
153
+ defaultValue: string
154
+ ): IEvalDetail<string>;
155
+
156
+ /**
157
+ * Calculates the JSON value of a feature flag for a given user.
158
+ *
159
+ * If the flag variation does not have a JSON value, {@link defaultValue} is returned.
160
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
161
+ * does not match any existing flag), {@link defaultValue} is returned.
162
+ *
163
+ * @param key
164
+ * The unique key of the feature flag.
165
+ * @param defaultValue
166
+ * The default value to return if the flag cannot be evaluated.
167
+ *
168
+ * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
169
+ */
170
+ jsonVariation(
171
+ key: string,
172
+ defaultValue: FlagValue
173
+ ): FlagValue;
174
+
175
+ /**
176
+ * Calculates the JSON value of a feature flag for a given user, and returns an object that
177
+ * describes the way the value was determined.
178
+ *
179
+ * If the flag variation does not have a JSON value, {@link defaultValue} is returned.
180
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
181
+ * does not match any existing flag), {@link defaultValue} is returned.
182
+ *
183
+ * @param key
184
+ * The unique key of the feature flag.
185
+ * @param defaultValue
186
+ * The default value to return if the flag cannot be evaluated.
187
+ *
188
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
189
+ */
190
+ jsonVariationDetail(
191
+ key: string,
192
+ defaultValue: FlagValue
193
+ ): IEvalDetail<FlagValue>;
194
+
195
+ /**
196
+ * Calculates the string value of a feature flag for a given user.
197
+ *
198
+ * If the flag variation does not have a string value, {@link defaultValue} is returned.
199
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
200
+ * does not match any existing flag), {@link defaultValue} is returned.
201
+ *
202
+ * @param key
203
+ * The unique key of the feature flag.
204
+ * @param defaultValue
205
+ * The default value to return if the flag cannot be evaluated.
206
+ *
207
+ * @returns the variation for the given user, or {@link defaultValue} if the flag cannot be evaluated
208
+ */
209
+ variation(
210
+ key: string,
211
+ defaultValue: FlagValue
212
+ ): FlagValue;
213
+
214
+ /**
215
+ * Calculates the string value of a feature flag for a given user, and returns an object that
216
+ * describes the way the value was determined.
217
+ *
218
+ * If the flag variation does not have a string value, {@link defaultValue} is returned.
219
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
220
+ * does not match any existing flag), {@link defaultValue} is returned.
221
+ *
222
+ * @param key
223
+ * The unique key of the feature flag.
224
+ * @param defaultValue
225
+ * The default value to return if the flag cannot be evaluated.
226
+ *
227
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
228
+ */
229
+ variationDetail(
230
+ key: string,
231
+ defaultValue: FlagValue
232
+ ): IEvalDetail<FlagValue>;
233
+
234
+ /**
235
+ * This method is exposed only for testing purpose, please DO NOT USE IT
236
+ *
237
+ * Calculates the value of a feature flag for a given user, and returns a {@link IEvalDetail} object that
238
+ * describes the way the value was determined.
239
+ *
240
+ * If an error makes it impossible to evaluate the flag (for instance, the feature flag key
241
+ * does not match any existing flag), {@link defaultValue} is returned.
242
+ *
243
+ * @param flagKey
244
+ * The unique key of the feature flag.
245
+ * @param defaultValue
246
+ * The default value to return if the flag cannot be evaluated.
247
+ * @param typeConverter
248
+ * the function to convert result, if null, the value returned will have the same type of the flag defined in FeatBit
249
+ *
250
+ * @returns {@link IEvalDetail} object describing the way the value was determined.
251
+ */
252
+ evaluateCore<TValue>(
253
+ flagKey: string,
254
+ defaultValue: TValue,
255
+ typeConverter?: (value: string) => IConvertResult<TValue>
256
+ ): IEvalDetail<TValue>;
257
+
258
+ /**
259
+ * Returns the variation with of all feature flags for a given user, and returns an object that
260
+ * describes the way the value was determined for each flag.
261
+ *
262
+ * @returns A list of {@link IEvalDetail} objects describing the way the values were determined.
263
+ */
264
+ getAllVariations(): Promise<IEvalDetail<string>[]>;
265
+
266
+ /**
267
+ * Shuts down the client and releases any resources it is using.
268
+ *
269
+ * @returns A promise that resolves when the client has been shut down.
270
+ */
271
+ close(): Promise<void>;
272
+
273
+ /**
274
+ * Tracks that an application-defined event occurred, and provides an additional numeric value for custom metrics.
275
+ *
276
+ * @param eventName
277
+ * the name of the event.
278
+ * @param metricValue
279
+ * a numeric value used by the FeatBit experimentation feature in custom numeric metrics, the default value is 1 if not provided.
280
+ */
281
+ track(eventName: string, metricValue?: number | undefined): void
282
+
283
+ /**
284
+ * Tells the client that all pending events (if any) should be delivered as soon as possible.
285
+ *
286
+ * @param callback
287
+ * Will be called when the flush operation is complete. If the flush fails, the callback will be called with false.
288
+ *
289
+ * @returns A promise that resolves when the client has been shut down.
290
+ */
291
+ flush(callback?: (res: boolean) => void): Promise<boolean>;
291
292
  }
@@ -1,18 +1,18 @@
1
- /**
2
- * Used internally to describe the basic properties of stored data such as feature flags or user
3
- * segments.
4
- *
5
- * This is the actual type of parameters and return values in `IStore` methods that refer
6
- * to a flag or segment item. Those methods still use the `object` type for backward compatibility.
7
- */
8
- export interface IVersionedData {
9
- /**
10
- * The item's unique key, such as a feature flag key.
11
- */
12
- key: string;
13
-
14
- /**
15
- * A version number that FeatBit will increment each time this item is changed.
16
- */
17
- version: number;
18
- }
1
+ /**
2
+ * Used internally to describe the basic properties of stored data such as feature flags or user
3
+ * segments.
4
+ *
5
+ * This is the actual type of parameters and return values in `IStore` methods that refer
6
+ * to a flag or segment item. Those methods still use the `object` type for backward compatibility.
7
+ */
8
+ export interface IVersionedData {
9
+ /**
10
+ * The item's unique key, such as a feature flag key.
11
+ */
12
+ key: string;
13
+
14
+ /**
15
+ * A version number that FeatBit will increment each time this item is changed.
16
+ */
17
+ version: number;
18
+ }
@@ -1,5 +1,5 @@
1
- import { IDataSourceUpdates } from "../store/IDataSourceUpdates";
2
-
3
- export interface IBootstrapProvider {
4
- populate(userKeyId: string, dataSourceUpdates: IDataSourceUpdates, callback?: () => void): Promise<void>
1
+ import { IDataSourceUpdates } from "../store/IDataSourceUpdates";
2
+
3
+ export interface IBootstrapProvider {
4
+ populate(userKeyId: string, dataSourceUpdates: IDataSourceUpdates, callback?: () => void): Promise<void>
5
5
  }