Client
OpenfuseCloud and Openfuse API reference
OpenfuseCloud
Pre-configured client for Openfuse Cloud. Extends Openfuse.
import { OpenfuseCloud } from '@openfuseio/sdk'
const client = new OpenfuseCloud(options: TOpenfuseCloudOptions)Constructor options
type TOpenfuseCloudOptions = {
system: string
clientId: string
clientSecret: string
metrics?: Partial<TMetricsConfig>
instanceId?: string
}| Option | Type | Required | Description |
|---|---|---|---|
system | string | Yes | System slug that groups related breakers. |
clientId | string | Yes | SDK client ID from the dashboard. |
clientSecret | string | Yes | SDK client secret from the dashboard. |
metrics | Partial<TMetricsConfig> | No | Override default metrics configuration. |
instanceId | string | No | Custom instance ID. Auto-detected if omitted. |
Throws ConfigurationError if required options are missing.
Openfuse
Base client for self-hosted deployments.
import { Openfuse } from '@openfuseio/sdk'
const client = new Openfuse(options: TOpenfuseOptions)Constructor options
type TOpenfuseOptions = {
baseUrl: string
system: string
clientId: string
clientSecret: string
metrics?: Partial<TMetricsConfig>
instanceId?: string
}| Option | Type | Required | Description |
|---|---|---|---|
baseUrl | string | Yes | Your Openfuse API base URL. |
system | string | Yes | System slug that groups related breakers. |
clientId | string | Yes | SDK client ID. |
clientSecret | string | Yes | SDK client secret. |
metrics | Partial<TMetricsConfig> | No | Override default metrics configuration. |
instanceId | string | No | Custom instance ID. Auto-detected if omitted. |
Throws ConfigurationError if required options are missing.
Methods
init()
init(options?: { timeoutMs?: number; maxAttempts?: number }): voidAuthenticates with the Openfuse API, fetches server configuration, and pre-caches breaker states. Runs in the background.
Never throws. Errors are logged and retried with exponential backoff. Calling init() twice is a no-op if the first attempt is still in progress.
client.init()
client.init({ timeoutMs: 3000, maxAttempts: 5 })ready()
ready(): Promise<void>Resolves when the current init() attempt completes. Resolves immediately if init() hasn't been called or has already finished.
client.init()
await client.ready()breaker()
breaker(slug: string): BreakerHandleReturns a BreakerHandle bound to the given slug. No API call is made.
const stripe = client.breaker('stripe-api')breakers()
breakers(): Promise<TBreaker[]>Returns all breakers for the configured system. Returns [] if not initialized or the API is unreachable. Never throws. Has a 500ms budget.
const allBreakers = await client.breakers()
for (const b of allBreakers) {
console.log(`${b.slug}: ${b.state}`)
}reset()
reset(): Promise<void>Clears all cached breaker data, flushes pending metrics, and resets API health tracking. Does not re-run init(). Never throws.
await client.reset()close()
close(options?: { timeoutMs?: number }): Promise<void>Cancels init retries, flushes pending metrics, and stops the metrics timer. Never throws.
| Option | Type | Default | Description |
|---|---|---|---|
timeoutMs | number | 5000 | Max time to wait for the metrics flush. |
await client.close({ timeoutMs: 3000 })flushMetrics()
flushMetrics(): Promise<void>Sends all buffered metrics to the backend immediately. Does not stop the flush timer. Never throws.
await client.flushMetrics()stopMetrics()
stopMetrics(): voidStops the background metrics flush timer. The timer restarts on the next protect() call. Never throws.
client.stopMetrics()instanceId
get instanceId(): stringThe unique instance ID for this SDK process. Auto-generated from the platform environment or set via constructor options.
console.log(client.instanceId)