@reflag/node-sdk 1.0.0-alpha.1 → 1.0.0-alpha.3
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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Node.js, JavaScript/TypeScript client for [Reflag.com](https://reflag.com).
|
|
4
4
|
|
|
5
|
-
Reflag supports
|
|
5
|
+
Reflag supports flag toggling, tracking flag usage, collecting feedback on features, and [remotely configuring flags](#remote-config).
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -54,6 +54,22 @@ Other supported languages/frameworks are in the [Supported languages](https://do
|
|
|
54
54
|
|
|
55
55
|
You can also [use the HTTP API directly](https://docs.reflag.com/api/http-api)
|
|
56
56
|
|
|
57
|
+
## Migrating from Bucket SDK
|
|
58
|
+
|
|
59
|
+
If you have been using the Bucket SDKs, the following list will help you migrate to Reflag SDK:
|
|
60
|
+
|
|
61
|
+
- `Bucket*` classes, and types have been renamed to `Reflag*` (e.g. `BucketClient` is now `ReflagClient`)
|
|
62
|
+
- `Feature*` classes, and types have been renamed to `Feature*` (e.g. `Feature` is now `Flag`, `RawFeatures` is now `RawFlags`)
|
|
63
|
+
- When using strongly-typed flags, the new `Flags` interface replaced `Features` interface
|
|
64
|
+
- All methods that contained `feature` in the name have been renamed to use the `flag` terminology (e.g. `getFeature` is `getFlag`)
|
|
65
|
+
- All environment variables that were prefixed with `BUCKET_` are now prefixed with `REFLAG_`
|
|
66
|
+
- The `BUCKET_HOST` environment variable and `host` option have been removed from `ReflagClient` constructor, use `REFLAG_API_BASE_URL` instead
|
|
67
|
+
- The `BUCKET_FEATURES_ENABLED` and `BUCKET_FEATURES_DISABLED` have been renamed to `REFLAG_FLAGS_ENABLED` and `REFLAG_FLAGS_DISABLED`
|
|
68
|
+
- The default configuration file has been renamed from `bucketConfig.json` to `reflag.config.json`
|
|
69
|
+
- The `fallbackFeatures` property in client constructor and configuration files has been renamed to `fallbackFlags`
|
|
70
|
+
- `featureKey` has been renamed to `flagKey` in all methods that accepts that argument
|
|
71
|
+
- The SDKs will not emit `evaluate` and `evaluate-config` events anymore
|
|
72
|
+
|
|
57
73
|
## Basic usage
|
|
58
74
|
|
|
59
75
|
To get started you need to obtain your secret key from the [environment settings](https://app.reflag.com/env-current/settings/app-environments)
|
|
@@ -79,7 +95,7 @@ import { ReflagClient } from "@reflag/node-sdk";
|
|
|
79
95
|
// to avoid multiple round-trips to our servers.
|
|
80
96
|
export const reflagClient = new ReflagClient();
|
|
81
97
|
|
|
82
|
-
// Initialize the client and begin fetching
|
|
98
|
+
// Initialize the client and begin fetching flag targeting definitions.
|
|
83
99
|
// You must call this method prior to any calls to `getFlags()`,
|
|
84
100
|
// otherwise an empty object will be returned.
|
|
85
101
|
reflagClient.initialize().then({
|
|
@@ -87,8 +103,8 @@ reflagClient.initialize().then({
|
|
|
87
103
|
})
|
|
88
104
|
```
|
|
89
105
|
|
|
90
|
-
Once the client is initialized, you can obtain
|
|
91
|
-
status to indicate whether the
|
|
106
|
+
Once the client is initialized, you can obtain flags along with the `isEnabled`
|
|
107
|
+
status to indicate whether the flag is targeted for this user/company:
|
|
92
108
|
|
|
93
109
|
> [!IMPORTANT]
|
|
94
110
|
> If `user.id` or `company.id` is not given, the whole `user` or `company` object is ignored.
|
|
@@ -109,13 +125,13 @@ const boundClient = reflagClient.bindClient({
|
|
|
109
125
|
},
|
|
110
126
|
});
|
|
111
127
|
|
|
112
|
-
// get the huddle
|
|
128
|
+
// get the huddle flag using company, user and custom context to
|
|
113
129
|
// evaluate the targeting.
|
|
114
130
|
const { isEnabled, track, config } = boundClient.getFlag("huddle");
|
|
115
131
|
|
|
116
132
|
if (isEnabled) {
|
|
117
|
-
// this is your
|
|
118
|
-
// send an event when the
|
|
133
|
+
// this is your flag gated code ...
|
|
134
|
+
// send an event when the flag is used:
|
|
119
135
|
track();
|
|
120
136
|
|
|
121
137
|
if (config?.key === "zoom") {
|
|
@@ -130,20 +146,19 @@ if (isEnabled) {
|
|
|
130
146
|
}
|
|
131
147
|
```
|
|
132
148
|
|
|
133
|
-
You can also use the `getFlags()` method which returns a map of all
|
|
149
|
+
You can also use the `getFlags()` method which returns a map of all flags:
|
|
134
150
|
|
|
135
151
|
```typescript
|
|
136
|
-
// get the current
|
|
137
|
-
// evaluate the
|
|
138
|
-
const
|
|
139
|
-
const bothEnabled =
|
|
140
|
-
features.huddle?.isEnabled && features.voiceHuddle?.isEnabled;
|
|
152
|
+
// get the current flags (uses company, user and custom context to
|
|
153
|
+
// evaluate the flags).
|
|
154
|
+
const flags = boundClient.getFlags();
|
|
155
|
+
const bothEnabled = flags.huddle?.isEnabled && flags.voiceHuddle?.isEnabled;
|
|
141
156
|
```
|
|
142
157
|
|
|
143
|
-
## High performance
|
|
158
|
+
## High performance flag targeting
|
|
144
159
|
|
|
145
160
|
The SDK contacts the Reflag servers when you call `initialize()`
|
|
146
|
-
and downloads the
|
|
161
|
+
and downloads the flags with their targeting rules.
|
|
147
162
|
These rules are then matched against the user/company information you provide
|
|
148
163
|
to `getFlags()` (or through `bindClient(..).getFlags()`). That means the
|
|
149
164
|
`getFlags()` call does not need to contact the Reflag servers once
|
|
@@ -152,7 +167,7 @@ download the targeting rules from the Reflag servers in the background.
|
|
|
152
167
|
|
|
153
168
|
### Batch Operations
|
|
154
169
|
|
|
155
|
-
The SDK automatically batches operations like user/company updates and
|
|
170
|
+
The SDK automatically batches operations like user/company updates and flag tracking events to minimize API calls.
|
|
156
171
|
The batch buffer is configurable through the client options:
|
|
157
172
|
|
|
158
173
|
```typescript
|
|
@@ -175,8 +190,8 @@ await client.flush();
|
|
|
175
190
|
|
|
176
191
|
### Rate Limiting
|
|
177
192
|
|
|
178
|
-
The SDK includes automatic rate limiting for
|
|
179
|
-
Rate limiting is applied per unique combination of
|
|
193
|
+
The SDK includes automatic rate limiting for flag events to prevent overwhelming the API.
|
|
194
|
+
Rate limiting is applied per unique combination of flag key and context. The rate limiter window size is configurable:
|
|
180
195
|
|
|
181
196
|
```typescript
|
|
182
197
|
const client = new ReflagClient({
|
|
@@ -188,17 +203,17 @@ const client = new ReflagClient({
|
|
|
188
203
|
|
|
189
204
|
### Flag definitions
|
|
190
205
|
|
|
191
|
-
Flag definitions include the rules needed to determine which
|
|
206
|
+
Flag definitions include the rules needed to determine which flags should be enabled and which config values should be applied to any given user/company.
|
|
192
207
|
Flag definitions are automatically fetched when calling `initialize()`.
|
|
193
208
|
They are then cached and refreshed in the background.
|
|
194
|
-
It's also possible to get the currently in use
|
|
209
|
+
It's also possible to get the currently in use flag definitions:
|
|
195
210
|
|
|
196
211
|
```typescript
|
|
197
212
|
import fs from "fs";
|
|
198
213
|
|
|
199
214
|
const client = new ReflagClient();
|
|
200
215
|
|
|
201
|
-
const
|
|
216
|
+
const flagDefs = await client.getFlagDefinitions();
|
|
202
217
|
// [{
|
|
203
218
|
// key: "huddle",
|
|
204
219
|
// description: "Live voice conversations with colleagues."
|
|
@@ -224,17 +239,17 @@ export default {
|
|
|
224
239
|
// initialize the client and wait for it to complete
|
|
225
240
|
// if the client was initialized on a previous invocation, this is a no-op.
|
|
226
241
|
await reflag.initialize();
|
|
227
|
-
const
|
|
242
|
+
const flags = reflag.getFlags({
|
|
228
243
|
user: { id: "userId" },
|
|
229
244
|
company: { id: "companyId" },
|
|
230
245
|
});
|
|
231
246
|
|
|
232
|
-
// ensure all events are flushed and any requests to refresh the
|
|
247
|
+
// ensure all events are flushed and any requests to refresh the flag cache
|
|
233
248
|
// have completed after the response is sent
|
|
234
249
|
ctx.waitUntil(reflag.flush());
|
|
235
250
|
|
|
236
251
|
return new Response(
|
|
237
|
-
`Flags for user ${userId} and company ${companyId}: ${JSON.stringify(
|
|
252
|
+
`Flags for user ${userId} and company ${companyId}: ${JSON.stringify(flags, null, 2)}`,
|
|
238
253
|
);
|
|
239
254
|
},
|
|
240
255
|
};
|
|
@@ -242,9 +257,9 @@ export default {
|
|
|
242
257
|
|
|
243
258
|
See [examples/cloudflare-worker](examples/cloudflare-worker/src/index.ts) for a deployable example.
|
|
244
259
|
|
|
245
|
-
Reflag maintains a cached set of
|
|
260
|
+
Reflag maintains a cached set of flag definitions in the memory of your worker which it uses to decide which flags to turn on for which users/companies.
|
|
246
261
|
|
|
247
|
-
The SDK caches
|
|
262
|
+
The SDK caches flag definitions in memory for fast performance. The first request to a new worker instance fetches definitions from Reflag's servers, while subsequent requests use the cache. When the cache expires, it's updated in the background. `ctx.waitUntil(reflag.flush())` ensures completion of the background work, so response times are not affected. This background work may increase wall-clock time for your worker, but it will not measurably increase billable CPU time on platforms like Cloudflare.
|
|
248
263
|
|
|
249
264
|
## Error Handling
|
|
250
265
|
|
|
@@ -254,15 +269,15 @@ fallback behavior:
|
|
|
254
269
|
1. **Flag Evaluation Failures**:
|
|
255
270
|
|
|
256
271
|
```typescript
|
|
257
|
-
const { isEnabled } = client.getFlag("my-
|
|
258
|
-
// If
|
|
272
|
+
const { isEnabled } = client.getFlag("my-flag");
|
|
273
|
+
// If flag evaluation fails, isEnabled will be false
|
|
259
274
|
```
|
|
260
275
|
|
|
261
276
|
2. **Network Errors**:
|
|
262
277
|
|
|
263
278
|
```typescript
|
|
264
279
|
// Network errors during tracking are logged but don't affect your application
|
|
265
|
-
const { track } = client.getFlag("my-
|
|
280
|
+
const { track } = client.getFlag("my-flag");
|
|
266
281
|
if (isEnabled) {
|
|
267
282
|
try {
|
|
268
283
|
await track();
|
|
@@ -277,7 +292,7 @@ fallback behavior:
|
|
|
277
292
|
|
|
278
293
|
```typescript
|
|
279
294
|
// The SDK tracks missing context fields but continues operation
|
|
280
|
-
const
|
|
295
|
+
const flags = client.getFlags({
|
|
281
296
|
user: { id: "user123" },
|
|
282
297
|
// Missing company context will be logged but won't cause errors
|
|
283
298
|
});
|
|
@@ -286,11 +301,11 @@ fallback behavior:
|
|
|
286
301
|
4. **Offline Mode**:
|
|
287
302
|
|
|
288
303
|
```typescript
|
|
289
|
-
// In offline mode, the SDK uses
|
|
304
|
+
// In offline mode, the SDK uses flag overrides
|
|
290
305
|
const client = new ReflagClient({
|
|
291
306
|
offline: true,
|
|
292
|
-
|
|
293
|
-
"my-
|
|
307
|
+
flagOverrides: () => ({
|
|
308
|
+
"my-flag": true,
|
|
294
309
|
}),
|
|
295
310
|
});
|
|
296
311
|
```
|
|
@@ -314,14 +329,14 @@ const client = new ReflagClient({
|
|
|
314
329
|
|
|
315
330
|
## Remote config
|
|
316
331
|
|
|
317
|
-
Remote config is a dynamic and flexible approach to configuring
|
|
332
|
+
Remote config is a dynamic and flexible approach to configuring flag behavior outside of your app – without needing to re-deploy it.
|
|
318
333
|
|
|
319
|
-
Similar to `isEnabled`, each
|
|
320
|
-
It is managed similar to the way access to
|
|
334
|
+
Similar to `isEnabled`, each flag has a `config` property. This configuration is managed from within Reflag.
|
|
335
|
+
It is managed similar to the way access to flags is managed, but instead of the binary `isEnabled` you can have
|
|
321
336
|
multiple configuration values which are given to different user/companies.
|
|
322
337
|
|
|
323
338
|
```ts
|
|
324
|
-
const
|
|
339
|
+
const flags = reflagClient.getFlags();
|
|
325
340
|
// {
|
|
326
341
|
// huddle: {
|
|
327
342
|
// isEnabled: true,
|
|
@@ -334,7 +349,7 @@ const features = reflagClient.getFlags();
|
|
|
334
349
|
// }
|
|
335
350
|
```
|
|
336
351
|
|
|
337
|
-
`key` is mandatory for a config, but if a
|
|
352
|
+
`key` is mandatory for a config, but if a flag has no config or no config value was matched against the context, the `key` will be `undefined`. Make sure to check against this case when trying to use the configuration in your application. `payload` is an optional JSON value for arbitrary configuration needs.
|
|
338
353
|
|
|
339
354
|
Just as `isEnabled`, accessing `config` on the object returned by `getFlags` does not automatically
|
|
340
355
|
generate a `check` event, contrary to the `config` property on the object returned by `getFlag`.
|
|
@@ -346,16 +361,16 @@ a configuration file on disk or by passing options to the `ReflagClient`
|
|
|
346
361
|
constructor. By default, the SDK searches for `reflag.config.json` in the
|
|
347
362
|
current working directory.
|
|
348
363
|
|
|
349
|
-
| Option
|
|
350
|
-
|
|
|
351
|
-
| `secretKey`
|
|
352
|
-
| `logLevel`
|
|
353
|
-
| `offline`
|
|
354
|
-
| `apiBaseUrl`
|
|
355
|
-
| `
|
|
356
|
-
| `configFile`
|
|
364
|
+
| Option | Type | Description | Env Var |
|
|
365
|
+
| --------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
|
|
366
|
+
| `secretKey` | string | The secret key used for authentication with Reflag's servers. | REFLAG_SECRET_KEY |
|
|
367
|
+
| `logLevel` | string | The log level for the SDK (e.g., `"DEBUG"`, `"INFO"`, `"WARN"`, `"ERROR"`). Default: `INFO` | REFLAG_LOG_LEVEL |
|
|
368
|
+
| `offline` | boolean | Operate in offline mode. Default: `false`, except in tests it will default to `true` based off of the `TEST` env. var. | REFLAG_OFFLINE |
|
|
369
|
+
| `apiBaseUrl` | string | The base API URL for the Reflag servers. | REFLAG_API_BASE_URL |
|
|
370
|
+
| `flagOverrides` | Record<string, boolean> | An object specifying flag overrides for testing or local development. See [examples/express/app.test.ts](https://github.com/reflagcom/javascript/tree/main/packages/node-sdk/examples/express/app.test.ts) for how to use `flagOverrides` in tests. | REFLAG_FLAGS_ENABLED, REFLAG_FLAGS_DISABLED |
|
|
371
|
+
| `configFile` | string | Load this config file from disk. Default: `reflag.config.json` | REFLAG_CONFIG_FILE |
|
|
357
372
|
|
|
358
|
-
> [!NOTE] > `REFLAG_FLAGS_ENABLED` and `REFLAG_FLAGS_DISABLED` are comma separated lists of
|
|
373
|
+
> [!NOTE] > `REFLAG_FLAGS_ENABLED` and `REFLAG_FLAGS_DISABLED` are comma separated lists of flags which will be enabled or disabled respectively.
|
|
359
374
|
|
|
360
375
|
`reflag.config.json` example:
|
|
361
376
|
|
|
@@ -394,18 +409,18 @@ order of importance:
|
|
|
394
409
|
|
|
395
410
|
To get type checked flags, install the Reflag CLI:
|
|
396
411
|
|
|
397
|
-
```
|
|
412
|
+
```sh
|
|
398
413
|
npm i --save-dev @reflag/cli
|
|
399
414
|
```
|
|
400
415
|
|
|
401
416
|
then generate the types:
|
|
402
417
|
|
|
403
|
-
```
|
|
404
|
-
npx reflag
|
|
418
|
+
```sh
|
|
419
|
+
npx reflag flags types
|
|
405
420
|
```
|
|
406
421
|
|
|
407
|
-
This will generate a `reflag.d.ts` containing all your
|
|
408
|
-
Any
|
|
422
|
+
This will generate a `reflag.d.ts` containing all your flags.
|
|
423
|
+
Any flag look ups will now be checked against the flags that exist in Reflag.
|
|
409
424
|
|
|
410
425
|
Here's an example of a failed type check:
|
|
411
426
|
|
|
@@ -417,8 +432,8 @@ export const reflagClient = new ReflagClient();
|
|
|
417
432
|
reflagClient.initialize().then(() => {
|
|
418
433
|
console.log("Reflag initialized!");
|
|
419
434
|
|
|
420
|
-
// TypeScript will catch this error: "invalid-
|
|
421
|
-
reflagClient.getFlag("invalid-
|
|
435
|
+
// TypeScript will catch this error: "invalid-flag" doesn't exist
|
|
436
|
+
reflagClient.getFlag("invalid-flag");
|
|
422
437
|
|
|
423
438
|
const {
|
|
424
439
|
isEnabled,
|
|
@@ -444,7 +459,7 @@ reflagClient.initialize().then(() => {
|
|
|
444
459
|
|
|
445
460
|
## Testing
|
|
446
461
|
|
|
447
|
-
When writing tests that cover code with flags, you can toggle
|
|
462
|
+
When writing tests that cover code with flags, you can toggle flags on/off programmatically to test the different behavior.
|
|
448
463
|
|
|
449
464
|
`reflag.ts`:
|
|
450
465
|
|
|
@@ -466,7 +481,7 @@ afterEach(() => {
|
|
|
466
481
|
|
|
467
482
|
describe("API Tests", () => {
|
|
468
483
|
it("should return 200 for the root endpoint", async () => {
|
|
469
|
-
reflag.
|
|
484
|
+
reflag.flagOverrides = {
|
|
470
485
|
"show-todo": true,
|
|
471
486
|
};
|
|
472
487
|
|
|
@@ -477,7 +492,7 @@ describe("API Tests", () => {
|
|
|
477
492
|
});
|
|
478
493
|
```
|
|
479
494
|
|
|
480
|
-
See more on
|
|
495
|
+
See more on flag overrides in the section below.
|
|
481
496
|
|
|
482
497
|
## Flag Overrides
|
|
483
498
|
|
|
@@ -486,11 +501,11 @@ Flag overrides allow you to override flags and their configurations locally. Thi
|
|
|
486
501
|
1. Through environment variables:
|
|
487
502
|
|
|
488
503
|
```bash
|
|
489
|
-
REFLAG_FLAGS_ENABLED=
|
|
490
|
-
REFLAG_FLAGS_DISABLED=
|
|
504
|
+
REFLAG_FLAGS_ENABLED=flag1,flag2
|
|
505
|
+
REFLAG_FLAGS_DISABLED=flag3,flag4
|
|
491
506
|
```
|
|
492
507
|
|
|
493
|
-
|
|
508
|
+
1. Through `reflag.config.json`:
|
|
494
509
|
|
|
495
510
|
```json
|
|
496
511
|
{
|
|
@@ -509,17 +524,17 @@ REFLAG_FLAGS_DISABLED=feature3,feature4
|
|
|
509
524
|
}
|
|
510
525
|
```
|
|
511
526
|
|
|
512
|
-
|
|
527
|
+
1. Programmatically through the client options:
|
|
513
528
|
|
|
514
|
-
You can use a simple `Record<string, boolean>` and pass it either in the constructor or by setting `client.
|
|
529
|
+
You can use a simple `Record<string, boolean>` and pass it either in the constructor or by setting `client.flagOverrides`:
|
|
515
530
|
|
|
516
531
|
```typescript
|
|
517
532
|
// pass directly in the constructor
|
|
518
|
-
const client = new ReflagClient({
|
|
533
|
+
const client = new ReflagClient({ flagOverrides: { myFlag: true } });
|
|
519
534
|
// or set on the client at a later time
|
|
520
|
-
client.
|
|
535
|
+
client.flagOverrides = { myFlag: false };
|
|
521
536
|
|
|
522
|
-
// clear
|
|
537
|
+
// clear flag overrides. Same as setting to {}.
|
|
523
538
|
client.clearFlagOverrides();
|
|
524
539
|
```
|
|
525
540
|
|
|
@@ -528,7 +543,7 @@ To get dynamic overrides, use a function which takes a context and returns a boo
|
|
|
528
543
|
```typescript
|
|
529
544
|
import { ReflagClient, Context } from "@reflag/node-sdk";
|
|
530
545
|
|
|
531
|
-
const
|
|
546
|
+
const flagOverrides = (context: Context) => ({
|
|
532
547
|
"delete-todos": {
|
|
533
548
|
isEnabled: true,
|
|
534
549
|
config: {
|
|
@@ -542,13 +557,13 @@ const featureOverrides = (context: Context) => ({
|
|
|
542
557
|
});
|
|
543
558
|
|
|
544
559
|
const client = new ReflagClient({
|
|
545
|
-
|
|
560
|
+
flagOverrides,
|
|
546
561
|
});
|
|
547
562
|
```
|
|
548
563
|
|
|
549
564
|
## Remote Flag Evaluation
|
|
550
565
|
|
|
551
|
-
In addition to local
|
|
566
|
+
In addition to local flag evaluation, Reflag supports remote evaluation using stored context. This is useful when you want to evaluate flags using user/company attributes that were previously sent to Reflag:
|
|
552
567
|
|
|
553
568
|
```typescript
|
|
554
569
|
// First, update user and company attributes
|
|
@@ -566,33 +581,29 @@ await client.updateCompany("company456", {
|
|
|
566
581
|
},
|
|
567
582
|
});
|
|
568
583
|
|
|
569
|
-
// Later, evaluate
|
|
570
|
-
const
|
|
571
|
-
// Or evaluate a single
|
|
572
|
-
const
|
|
584
|
+
// Later, evaluate flags remotely using stored context
|
|
585
|
+
const flags = await client.getFlagsRemote("company456", "user123");
|
|
586
|
+
// Or evaluate a single flag
|
|
587
|
+
const flag = await client.getFlagRemote(
|
|
573
588
|
"create-todos",
|
|
574
589
|
"company456",
|
|
575
590
|
"user123",
|
|
576
591
|
);
|
|
577
592
|
|
|
578
593
|
// You can also provide additional context
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
other: {
|
|
584
|
-
location: "US",
|
|
585
|
-
platform: "mobile",
|
|
586
|
-
},
|
|
594
|
+
const flagsWithContext = await client.getFlagsRemote("company456", "user123", {
|
|
595
|
+
other: {
|
|
596
|
+
location: "US",
|
|
597
|
+
platform: "mobile",
|
|
587
598
|
},
|
|
588
|
-
);
|
|
599
|
+
});
|
|
589
600
|
```
|
|
590
601
|
|
|
591
602
|
Remote evaluation is particularly useful when:
|
|
592
603
|
|
|
593
604
|
- You want to use the most up-to-date user/company attributes stored in Reflag
|
|
594
605
|
- You don't want to pass all context attributes with every evaluation
|
|
595
|
-
- You need to ensure consistent
|
|
606
|
+
- You need to ensure consistent flag evaluation across different services
|
|
596
607
|
|
|
597
608
|
## Using with Express
|
|
598
609
|
|
|
@@ -662,7 +673,7 @@ See [examples/express/app.ts](https://github.com/reflagcom/javascript/tree/main/
|
|
|
662
673
|
If you don't want to provide context each time when evaluating flags but
|
|
663
674
|
rather you would like to utilize the attributes you sent to Reflag previously
|
|
664
675
|
(by calling `updateCompany` and `updateUser`) you can do so by calling `getFlagsRemote`
|
|
665
|
-
(or `getFlagRemote` for a specific
|
|
676
|
+
(or `getFlagRemote` for a specific flag) with providing just `userId` and `companyId`.
|
|
666
677
|
These methods will call Reflag's servers and flags will be evaluated remotely
|
|
667
678
|
using the stored attributes.
|
|
668
679
|
|
|
@@ -684,7 +695,7 @@ client.updateCompany("acme_inc", {
|
|
|
684
695
|
...
|
|
685
696
|
|
|
686
697
|
// This will evaluate flags with respecting the attributes sent previously
|
|
687
|
-
const
|
|
698
|
+
const flags = await client.getFlagsRemote("acme_inc", "john_doe");
|
|
688
699
|
```
|
|
689
700
|
|
|
690
701
|
> [!IMPORTANT]
|
package/dist/package.json
CHANGED
|
@@ -37,7 +37,7 @@ function periodicallyUpdatingCache(ttl, staleTtl, logger, fn) {
|
|
|
37
37
|
if (newValue === undefined) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
logger === null || logger === void 0 ? void 0 : logger.info("refreshed
|
|
40
|
+
logger === null || logger === void 0 ? void 0 : logger.info("refreshed flag definitions");
|
|
41
41
|
cachedValue = newValue;
|
|
42
42
|
lastUpdate = Date.now();
|
|
43
43
|
logger === null || logger === void 0 ? void 0 : logger.debug("updated cached value", cachedValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"periodicallyUpdatingCache.js","sourceRoot":"","sources":["../../src/periodicallyUpdatingCache.ts"],"names":[],"mappings":";;;;;;;;;;;AAeA,4CAgEC;AA7ED;;;;;;;;;;;;IAYI;AACJ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4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@reflag/flag-evaluation": "1.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d82ab8460d83e490b4e6fd2a20897305445c7f06"
|
|
50
50
|
}
|