Skip to main content
All public API is in the dev.westyx.nexus package.

Factory

NexusClient.create

Creates a new NexusClient and performs an initial synchronous sync before returning. Throws NexusInitException wrapping any underlying failure if the initial sync does not succeed. The engine parameter is optional and is intended for testing with MockEngine.

Config / secret / flag getters

All getters call ensureFresh() internally, which triggers a background sync if the snapshot is older than config.ttl. They never block on the network call - the stale value is returned immediately while sync runs in the background.

getString

Returns the string value for key from the config snapshot, or default if the key is not present or the value is empty.

getBoolean

Returns the boolean value for key. Parses "true" / "false" (case-insensitive strict). Returns default if the key is missing or the value cannot be parsed.

getInt

Returns the integer value for key. Returns default if the key is missing or the value is not a valid integer.

getDouble

Returns the double value for key. Returns default if the key is missing or the value is not a valid double.

getJson

Returns the raw JsonElement value stored in the snapshot for key, or null if not found. Use when the value type is not known at compile time.

getFlag

Returns true if the feature flag key is active, false if it is inactive, or default if the key is not found in the flags snapshot.

getSecret

Returns the plaintext value of secret key from the in-memory snapshot. Throws:
  • NexusPublicKeyException - when the client was created with a wxp_... key
  • NexusServiceKindMismatchException - when the service is of kind frontend
  • NexusSecretNotFoundException - when key is not present in the secrets snapshot

getSecretFilePath

Returns the absolute path to a temporary file containing the value of secret key. Only available for secrets of type file. The file is created during sync and deleted when close() is called. Throws:
  • NexusPublicKeyException - when the client was created with a wxp_... key
  • NexusSecretNotFoundException - when key is not a known file-type secret

Write API (v0.5.0)

The write API allows programmatic secret creation and deletion. Available for secret keys only. Using a public key throws NexusPublicKeyException immediately, before the network call.

setSecret

Creates or updates a secret with the given key, plaintext value, and optional type (defaults to "text").
Throws:
  • NexusPublicKeyException - when the client uses a wxp_... key
  • NexusRateLimitedException - HTTP 429 on write endpoint
  • NexusUnauthorizedException - HTTP 401
  • NexusBillingException - HTTP 402 (billing overdue)
  • NexusException - any other error

deleteSecret

Deletes a secret and all its versions.
Throws:
  • NexusPublicKeyException - when the client uses a wxp_... key
  • NexusRateLimitedException - HTTP 429 on write endpoint
  • NexusUnauthorizedException - HTTP 401
  • NexusBillingException - HTTP 402 (billing overdue)
  • NexusException - any other error

deleteSecretVersion

Deletes a specific version of a secret.
Throws:
  • NexusPublicKeyException - when the client uses a wxp_... key
  • NexusRateLimitedException - HTTP 429 on write endpoint
  • NexusUnauthorizedException - HTTP 401
  • NexusBillingException - HTTP 402 (billing overdue)
  • NexusException - any other error

A/B evaluation

evaluateAB

Sends a server-side A/B evaluation request to POST /v1/flags/evaluate-ab. Returns a map of flag key to true/false for the given userId and optional attributes.
Throws:
  • NexusAbAddonNotAvailableException - when the A/B testing add-on is not active for this project (HTTP 403)
  • NexusException - for any other non-success HTTP status

Sync

sync

Manually triggers a full sync against GET /v1/sync. Uses ETag/If-None-Match to skip the response body when nothing has changed (304 Not Modified). Updates the in-memory snapshot atomically on success. Throws:
  • NexusUnauthorizedException - HTTP 401
  • NexusBillingException - HTTP 402 (also sets billing-overdue flag and calls observer.onBillingOverdue())
  • NexusNotFoundException - HTTP 404
  • NexusQuarantinedException - HTTP 429 with quarantine body

Stream

connectStream

Starts the SSE stream connection in a background coroutine. Config changes and flag toggles published on the Nexus platform trigger a sync() call automatically. The stream reconnects with exponential back-off on transient failures.

disconnectStream

Cancels all active stream coroutines and sets streamStatus to DISCONNECTED. Does not affect the background TTL sync or the HTTP client.

streamStatus

A StateFlow that reflects the current stream connection state. Possible values:

Lifecycle

close

Cancels the internal coroutine scope, closes both HTTP clients, and deletes all temp files written by getSecretFilePath. Call this when the application shuts down. After close(), the client is unusable.