@flipfeatureflag/core 0.1.6 → 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.
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/package.json +1 -1
- package/src/client.ts +25 -4
package/dist/index.js
CHANGED
|
@@ -231,7 +231,9 @@ var FlipFlagClient = class {
|
|
|
231
231
|
if (cached) {
|
|
232
232
|
return this.recordEvaluation(flagKey, cached);
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
if (!this.options.disableRefresh) {
|
|
235
|
+
void this.refresh([flagKey]);
|
|
236
|
+
}
|
|
235
237
|
return this.recordEvaluation(flagKey, {
|
|
236
238
|
value: defaultValue,
|
|
237
239
|
variationKey: "default",
|
|
@@ -286,7 +288,6 @@ var FlipFlagClient = class {
|
|
|
286
288
|
return this.refreshInFlight;
|
|
287
289
|
}
|
|
288
290
|
applyEvaluate(response) {
|
|
289
|
-
this.evaluations.clear();
|
|
290
291
|
for (const [key, evaluation] of Object.entries(response.flags)) {
|
|
291
292
|
this.evaluations.set(key, evaluation);
|
|
292
293
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -205,7 +205,9 @@ var FlipFlagClient = class {
|
|
|
205
205
|
if (cached) {
|
|
206
206
|
return this.recordEvaluation(flagKey, cached);
|
|
207
207
|
}
|
|
208
|
-
|
|
208
|
+
if (!this.options.disableRefresh) {
|
|
209
|
+
void this.refresh([flagKey]);
|
|
210
|
+
}
|
|
209
211
|
return this.recordEvaluation(flagKey, {
|
|
210
212
|
value: defaultValue,
|
|
211
213
|
variationKey: "default",
|
|
@@ -260,7 +262,6 @@ var FlipFlagClient = class {
|
|
|
260
262
|
return this.refreshInFlight;
|
|
261
263
|
}
|
|
262
264
|
applyEvaluate(response) {
|
|
263
|
-
this.evaluations.clear();
|
|
264
265
|
for (const [key, evaluation] of Object.entries(response.flags)) {
|
|
265
266
|
this.evaluations.set(key, evaluation);
|
|
266
267
|
}
|
package/package.json
CHANGED
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);
|
|
@@ -138,7 +143,9 @@ export class FlipFlagClient {
|
|
|
138
143
|
return this.recordEvaluation(flagKey, cached);
|
|
139
144
|
}
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
if (!this.options.disableRefresh) {
|
|
147
|
+
void this.refresh([flagKey]);
|
|
148
|
+
}
|
|
142
149
|
return this.recordEvaluation(flagKey, {
|
|
143
150
|
value: defaultValue,
|
|
144
151
|
variationKey: "default",
|
|
@@ -179,7 +186,7 @@ export class FlipFlagClient {
|
|
|
179
186
|
context: this.context,
|
|
180
187
|
flagKeys: keys,
|
|
181
188
|
});
|
|
182
|
-
this.applyEvaluate(response);
|
|
189
|
+
this.applyEvaluate(response, keys);
|
|
183
190
|
|
|
184
191
|
if (!this.status.ready) {
|
|
185
192
|
this.status.ready = true;
|
|
@@ -202,10 +209,24 @@ export class FlipFlagClient {
|
|
|
202
209
|
return this.refreshInFlight;
|
|
203
210
|
}
|
|
204
211
|
|
|
205
|
-
private applyEvaluate(response: SdkEvaluateResponse) {
|
|
206
|
-
|
|
212
|
+
private applyEvaluate(response: SdkEvaluateResponse, requestedKeys?: string[]) {
|
|
213
|
+
if (!requestedKeys) {
|
|
214
|
+
this.knownFlagKeys.clear();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const returnedKeys = new Set<string>();
|
|
207
218
|
for (const [key, evaluation] of Object.entries(response.flags)) {
|
|
208
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
|
+
}
|
|
209
230
|
}
|
|
210
231
|
this.status.updatedAt = response.updatedAt;
|
|
211
232
|
}
|