Skip to main content
Openfuse
Reference

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
}
OptionTypeRequiredDescription
systemstringYesSystem slug that groups related breakers.
clientIdstringYesSDK client ID from the dashboard.
clientSecretstringYesSDK client secret from the dashboard.
metricsPartial<TMetricsConfig>NoOverride default metrics configuration.
instanceIdstringNoCustom 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
}
OptionTypeRequiredDescription
baseUrlstringYesYour Openfuse API base URL.
systemstringYesSystem slug that groups related breakers.
clientIdstringYesSDK client ID.
clientSecretstringYesSDK client secret.
metricsPartial<TMetricsConfig>NoOverride default metrics configuration.
instanceIdstringNoCustom instance ID. Auto-detected if omitted.

Throws ConfigurationError if required options are missing.


Methods

init()

init(options?: { timeoutMs?: number; maxAttempts?: number }): void

Authenticates 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): BreakerHandle

Returns 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.

OptionTypeDefaultDescription
timeoutMsnumber5000Max 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(): void

Stops the background metrics flush timer. The timer restarts on the next protect() call. Never throws.

client.stopMetrics()

instanceId

get instanceId(): string

The unique instance ID for this SDK process. Auto-generated from the platform environment or set via constructor options.

console.log(client.instanceId)

On this page