CanaryGate
The main SDK class.
class CanaryGate {
constructor(apiKey: string, options?: CanaryGateOptions)
init(): Promise<void>
getFlag(key: string): FlagData | undefined
getFlags(): FlagData[]
isStale(): boolean
getLastSyncAt(): string | null
disconnect(): void
}CanaryGateOptions
type CanaryGateOptions = {
/** API base URL. Default: 'http://localhost:3001' */
baseUrl?: string
/** Environment slug. Defaults to the project default environment. */
environment?: string
/** Server environments only: enable real-time SSE streaming. Default: false */
stream?: boolean
/** Initial stream reconnect delay in ms. Default: 5000 */
reconnectDelay?: number
/** Maximum stream reconnect delay in ms. Default: 30000 */
maxReconnectDelay?: number
/** Time in ms without a server heartbeat before reconnecting the stream. Default: 65000 */
heartbeatTimeoutMs?: number
}FlagData
Union type representing any flag.
type FlagData = BooleanFlagData | RolloutFlagDataBooleanFlagData
type BooleanFlagData = {
key: string
type: 'boolean'
enabled: boolean
}RolloutFlagData
type RolloutFlagData = {
key: string
type: 'rollout'
enabled: boolean
percent: number
}Narrowing by type
Use type for safe narrowing:
const flag = canary.getFlag('new-dashboard')
if (flag?.type === 'rollout') {
// TypeScript knows flag is RolloutFlagData here
console.log(flag.percent)
}Full exports
import {
CanaryGate,
type CanaryGateOptions,
type FlagData,
type BooleanFlagData,
type RolloutFlagData
} from '@canarygate/sdk/js/client'
// Both entry points export the same types:
import { type FlagData as ServerFlagData } from '@canarygate/sdk/js/server'Last updated on