FlagFix
SDKs

JavaScript browser SDK

createFlagFix from @flagfix/browser.

لا توجد ترجمة عربية منشورة لهذه الصفحة بعد. النص الإنجليزي هو المرجع.

Last updated on

@flagfix/browser is the client SDK for SPAs and browser bundles. It evaluates flags with evaluate-public, streams updates over SSE (unless disabled), and queues events to /api/v1/ingest. Set apiHost to https://api.flagfix.io, or to the API host your company uses.

import { createFlagFix } from "@flagfix/browser";

const client = createFlagFix({
  clientKey: process.env.NEXT_PUBLIC_FLAGFIX_CLIENT_KEY!,
  apiHost: process.env.NEXT_PUBLIC_FLAGFIX_API_HOST ?? "https://api.flagfix.io",
  storage: { mode: "persistent" },
});
await client.start();
MethodReturns
start()Promise<StartResult> with ready, storageMode, persistenceLevel, optional reason
identify(userId, traits?)TrackReceipt. Drops the previous flag snapshot
setTraits / setTrait / resetvoid
track(name, properties?)TrackReceipt
trackDurable(name, properties?)Promise<TrackDurableResult>
trackExposure(key, details?)receipt, or { queued: false, reason: "DUPLICATE_EXPOSURE" }
hasFeature(key, { fallback? })boolean. Does not emit an exposure
getValue(key, { fallback? })the flag value or the fallback
getAllFlags()Record<string, FlagResult>
getFlagMeta() / getFlagState()version, source, etag
refreshFlags()Promise<FlagState | null>
subscribeFlags(listener)unsubscribe function
flush(timeoutMs?) / shutdown(timeoutMs?)Promise<FlushResult>
resumeExport() / isExportSuspended()after HTTP 401 or 403
getIdentity()IdentityState
diagnostics()Promise<DiagnosticsSnapshot>

Evaluation mode is "public" (evaluate-public). SSE is on unless flags overrides it. lifecycle: false disables the document listener in tests. An empty clientKey throws.

هل كانت هذه الصفحة مفيدة؟