The @canarygate/sdk/js package is the official client for integrating CanaryGate into JavaScript and TypeScript applications. It is split into two entry points:
@canarygate/sdk/js/client— for browsers. Always uses the snapshot request and never opens SSE.@canarygate/sdk/js/server— for server runtimes (Node.js, Deno, Bun, Edge). Supports real-time SSE streaming withstream: true.
There is no root entry point (@canarygate/sdk or @canarygate/sdk/js); always import one of the two paths above.
Compatibility
| Environment | Support |
|---|---|
| Browser (modern) | ✓ |
| Node.js 18+ | ✓ |
| Deno | ✓ (via npm) |
| Bun | ✓ |
| Edge Runtime (Cloudflare Workers, Vercel Edge) | Partial* |
*The client entry (@canarygate/sdk/js/client) always uses the snapshot request and never opens SSE. On server runtimes (Node.js, Deno, Bun, Edge) import @canarygate/sdk/js/server and set stream: true to enable streaming via fetch-based SSE.
Installation
npm install @canarygate/sdk/jsFull API
| Method | Description |
|---|---|
new CanaryGate(apiKey, options?) | Creates the client |
init() | Loads flags via snapshot; starts SSE in server environments with stream: true |
getFlag(key) | Returns FlagData | undefined |
getFlags() | Returns FlagData[] (all flags) |
isStale() | true if the connection is degraded |
getLastSyncAt() | string | null of the last sync |
disconnect() | Closes the stream connection (if any) and releases resources |
Next steps
Last updated on