@flipfeatureflag/core 0.1.7 → 0.1.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.ts +22 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipfeatureflag/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "flipFeatureFlag core SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
package/src/client.ts CHANGED
@@ -22,6 +22,7 @@ export class FlipFlagClient {
22
22
  private emitter = new Emitter();
23
23
  private status: FlagsStatus = { ready: false };
24
24
  private evaluations = new Map<string, SdkFlagEvaluation>();
25
+ private knownFlagKeys = new Set<string>();
25
26
  private refreshTimer?: ReturnType<typeof setInterval>;
26
27
  private metricsTimer?: ReturnType<typeof setInterval>;
27
28
  private metricsBuffer = new MetricsBuffer();
@@ -123,6 +124,10 @@ export class FlipFlagClient {
123
124
  return result;
124
125
  }
125
126
 
127
+ hasFlag(flagKey: string): boolean {
128
+ return this.knownFlagKeys.has(flagKey);
129
+ }
130
+
126
131
  isEnabled(flagKey: string, defaultValue: boolean = false): boolean {
127
132
  const evaluation = this.evaluate(flagKey, defaultValue);
128
133
  return Boolean(evaluation.value);
@@ -181,7 +186,7 @@ export class FlipFlagClient {
181
186
  context: this.context,
182
187
  flagKeys: keys,
183
188
  });
184
- this.applyEvaluate(response);
189
+ this.applyEvaluate(response, keys);
185
190
 
186
191
  if (!this.status.ready) {
187
192
  this.status.ready = true;
@@ -204,9 +209,24 @@ export class FlipFlagClient {
204
209
  return this.refreshInFlight;
205
210
  }
206
211
 
207
- private applyEvaluate(response: SdkEvaluateResponse) {
212
+ private applyEvaluate(response: SdkEvaluateResponse, requestedKeys?: string[]) {
213
+ if (!requestedKeys) {
214
+ this.knownFlagKeys.clear();
215
+ }
216
+
217
+ const returnedKeys = new Set<string>();
208
218
  for (const [key, evaluation] of Object.entries(response.flags)) {
209
219
  this.evaluations.set(key, evaluation);
220
+ this.knownFlagKeys.add(key);
221
+ returnedKeys.add(key);
222
+ }
223
+
224
+ if (requestedKeys) {
225
+ for (const key of requestedKeys) {
226
+ if (!returnedKeys.has(key)) {
227
+ this.knownFlagKeys.delete(key);
228
+ }
229
+ }
210
230
  }
211
231
  this.status.updatedAt = response.updatedAt;
212
232
  }