Configuration
Beam aims for a minimal, predictable configuration surface. You can use a dedicated instance or the provided singleton.
BeamConfig
Beam(), beam(), and configureBeam() accept a BeamConfig configuration object with the following options:
tokenPath?: string(default:/beam/token) — GET endpoint that sets a JWT cookie used for authtokenCookie?: string(default:BEAM-TOKEN) — cookie name where the JWT is storedclockSkewSeconds?: number(default:30) — allowed skew when validating JWTexp
baseUrl
- Defaults to
window.location.originorprocess.env.SERVER_URL - Endpoints used by the SDK:
- GET
${baseUrl}${tokenPath}to establish a JWT cookie - POST
${baseUrl}${path}for feature flag evaluation
- GET
path
- Base path for Feature Flag requests
- Defaults to
/beam/feature-flag
defaultScope
- Default scope to use for all feature flag requests
- Can be overriden per request
headers
- Merged into the request headers for all SDK requests.
- Beam also auto-populates when available:
X-Requested-With: XMLHttpRequest- Bearer:
Authorization: Bearer <token>where the token is a JWT read from a cookie (default:BEAM-TOKEN) after aGETto${baseUrl}${tokenPath}(default:/beam/token). Tokens are validated for expiration and refreshed automatically.
- You can override by passing your own headers.
timeout
- Defaults to 5000ms.
- Set to
0orundefinedto disable client-side timeout.
global
- Defaults to
false. - Register the Beam instance globally at
globalThis.Beamfor easy access.
NOTE
React/Vue packages re-export
configureBeamand related types for convenience:
ts
// React
import { configureBeam } from '@beacon-hq/beam/react';
// Vue
import { configureBeam } from '@beacon-hq/beam/vue';Singleton helper
ts
import { beam } from '@beacon-hq/beam';
// First call creates the singleton
const Beam = beam();
// Subsequent calls return the same instance
const again = beam();
// Passing a config later re-creates the singleton
const replaced = beam({ path: '/flags' });Caching
- Each Beam instance maintains an in-memory cache keyed by flag + serialized context.
- Use
clearCache()to invalidate the entire instance cache.
ts
await beam().active('a'); // fetched and cached
beam().clearCache(); // next call will refetch