For the complete documentation index, see llms.txt. This page is also available as Markdown.

Management SDK

Typed SDK for interacting with Reflag’s Management API.

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

For a practical example of what you can build, see the Customer Admin Panel example app.

Installation

npm i @reflag/management-sdk
# or
yarn add @reflag/management-sdk

Create a client

Initialize the SDK with a Reflag Management API Key.

import { Api } from "@reflag/management-sdk";

const api = new Api({
  accessToken: process.env.REFLAG_API_KEY,
});

API surface

Main exports:

  • Api: base client

  • createAppClient(appId, config): app-scoped client

  • ReflagApiError: normalized API error type

  • Generated request/response types and models from @reflag/management-sdk

Core method groups:

  • Applications: listApps, getApp

  • Environments: listEnvironments, getEnvironment

  • Flags: listFlags, createFlag, updateFlag

  • User/company management: upsertUser, deleteUser, upsertCompany, deleteCompany

  • User/company evaluation: getUserFlags, updateUserFlags, getCompanyFlags, updateCompanyFlags

Quick start

App-scoped client

If most calls are for one app, use createAppClient to avoid repeating appId.

Common workflows

Create and update a flag

createFlag and updateFlag return the latest flag details together with flagStateVersions, keyed by environment ID.

Use null to clear nullable fields like description or ownerUserId on update.

Create, update, and delete entities

Use the entity management methods to synchronously manage users and companies in an environment. Entity attributes are merged with existing attributes.

Create a user and immediately enable a flag

Use upsertUser when the user must be available to a targeting request immediately, rather than relying on asynchronous runtime tracking ingestion. Await the upsert before enabling the flag. The flag must already exist, and the Management API key needs both write:entities and write:flag:targeting scopes.

The upsert makes the user available to the Management API. Refreshing the Node SDK requests the flag configuration containing the targeting change or newer; see Waiting for flag changes to reach an SDK. The same sequence works for companies using upsertCompany and updateCompanyFlags.

Read user flags for an environment

getUserFlags evaluates flag results for one user in one environment and returns the user’s current values plus exposure/check metadata for each flag.

Toggle a user flag

Use true to explicitly target on, and null to remove specific targeting.

Read company flags for an environment

Toggle a company flag

Use true to explicitly target on, and null to remove specific targeting.

Waiting for flag changes to reach an SDK

Flag changes can take a few seconds to propagate to evaluation SDKs. updateUserFlags and updateCompanyFlags return a flagStateVersion identifying the environment version containing the completed change. createFlag and updateFlag return flagStateVersions, keyed by environment ID.

With @reflag/node-sdk, pass this number to client.refreshFlags(version) before evaluating flags to request that version or newer, rather than waiting for the next automatic refresh. Use a client configured for the same app and environment.

For createFlag or updateFlag, pass result.flagStateVersions[envId] instead. The version is a minimum: a successful refresh may receive a newer version that also includes subsequent changes.

If the refresh fails, the Node SDK keeps its cached or fallback flags rather than throwing, so awaiting the call does not guarantee synchronization on failure.

Error handling

The SDK throws ReflagApiError for non-2xx API responses.

Example app

See packages/management-sdk/examples/customer-admin-panel/README.md for a small Next.js app using this SDK in server actions.

License

MIT

Last updated

Was this helpful?