Skip to content

Commit f3dcdae

Browse files
committed
docs(management-sdk): show synchronous user creation and flag targeting
1 parent 03990ce commit f3dcdae

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/management-sdk/README.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Typed SDK for interacting with Reflag’s Management API.
44

55
Use `@reflag/management-sdk` to programmatically manage feature flags such as listing flags, and enabling or disabling them for specific users or companies.
66

7-
For a practical example of what you can build, see the [Customer Admin Panel](https://github.com/reflagcom/javascript/blob/main/packages/rest-api-sdk/examples/customer-admin-panel/README.md) example app.
7+
For a practical example of what you can build, see the [Customer Admin Panel](https://github.com/reflagcom/javascript/blob/main/packages/management-sdk/examples/customer-admin-panel/README.md) example app.
88

99
## Installation
1010

@@ -207,6 +207,36 @@ await api.deleteCompany({
207207
});
208208
```
209209

210+
### Create a user and immediately enable a flag
211+
212+
Use `upsertUser` when the user must be available to a targeting request immediately,
213+
rather than relying on asynchronous runtime tracking ingestion. Await the upsert
214+
before enabling the flag. The flag must already exist, and the Management API key
215+
needs both `write:entities` and `write:flag:targeting` scopes.
216+
217+
```typescript
218+
const scope = { appId: "app-123", envId: "env-456" };
219+
const userId = "user-123";
220+
221+
await api.upsertUser({ ...scope, userId, name: "Jane Doe" });
222+
223+
const { flagStateVersion } = await api.updateUserFlags({
224+
...scope,
225+
userId,
226+
updates: [{ flagKey: "new-checkout", specificTargetValue: true }],
227+
});
228+
229+
// Optional: evaluate immediately using an initialized Node SDK client
230+
// configured for the same app and environment.
231+
await client.refreshFlags(flagStateVersion);
232+
const flag = client.getFlag("new-checkout", { user: { id: userId } });
233+
```
234+
235+
The upsert makes the user available to the Management API. Refreshing the Node SDK
236+
requests the flag configuration containing the targeting change or newer; see
237+
[Waiting for flag changes to reach an SDK](#waiting-for-flag-changes-to-reach-an-sdk).
238+
The same sequence works for companies using `upsertCompany` and `updateCompanyFlags`.
239+
210240
### Read user flags for an environment
211241

212242
`getUserFlags` evaluates flag results for one user in one environment and returns

0 commit comments

Comments
 (0)