Client lifecycle
Initialize, use, and shut down the SDK
init()
Call init() once at application startup:
const openfuse = new OpenfuseCloud({
system: 'payments',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
})
openfuse.init()init() is fire-and-forget. It returns void, never throws, and retries with exponential backoff on failure. If credentials are invalid, it logs an error and stops retrying.
Control retry behavior with options:
openfuse.init({
timeoutMs: 5000,
maxAttempts: 3,
})ready()
Wait for the current init attempt to complete:
openfuse.init()
await openfuse.ready()ready() is not required for normal usage. The SDK works immediately after init() with breakers defaulting to closed until state is fetched. Use ready() for tests and health checks where you need deterministic state.
reset()
Clear all cached breaker data, flush pending metrics, and reset API health tracking:
await openfuse.reset()Use reset() after adding or removing breakers in the dashboard. This forces the SDK to re-fetch on the next operation.
reset() does not re-run init(). Call init() again after reset() if you need to re-authenticate.
close()
Shut down the SDK gracefully:
await openfuse.close({ timeoutMs: 5000 })close() cancels in-progress init retries, flushes pending metrics, and stops the metrics timer. The timeoutMs option (default: 5000) limits how long the metrics flush can take.
Integrate with process signals
process.on('SIGTERM', async () => {
await openfuse.close({ timeoutMs: 3000 })
process.exit(0)
})stopMetrics / flushMetrics
For manual metrics control without full shutdown:
await openfuse.flushMetrics()
openfuse.stopMetrics()flushMetrics() sends buffered metrics immediately. stopMetrics() stops the background flush timer (restarts automatically on the next protect() call). Prefer close() for graceful shutdown.