dev.westyx.nexus package.
Factory
NexusClient.create
engine- the Ktor engine to use. The SDK bundles none, so when this is null exactly one engine artifact must be on the classpath. Pass one to share the application’s own configuration (proxy, TLS, connection pool). See Installation.metadataEngine- engine for cloud metadata/IMDS calls. The metadata client is separate and hardened (no redirects, no proxy, short timeout), which is why it is not simply the caller’s own HTTP client.
NexusConfigException- an invalid option, named in the message: a non-httpsbaseUrl, a non-positivettl, a blank or missingapiKey, ansseReconnectCooldownentry below one minuteNexusNoHttpEngineException- no Ktor engine availableNexusWifNotConfiguredException- WIF is enabled but no credential resolved; the client is not createdNexusInitException- the initial sync or session exchange failed, wrapping the cause
Config / secret / flag getters
All getters run a freshness check internally, which triggers a coalesced background sync if the snapshot is older thanconfig.ttl. They never block on the network and never throw because of a network problem - the cached value is returned immediately while the sync runs. See Caching behaviour.
getString
key from the config snapshot.
A JSON string is returned verbatim, including an intentionally empty one - an empty string is a value the service set, not a missing key. A JSON number or boolean is rendered as its literal text. An object or array yields default; use getJson for composite values.
getBoolean
key.
A JSON boolean is used directly. A JSON string is accepted when it reads exactly true or false (case-insensitive, trimmed), because a config surface may store a boolean as text. Anything else - "yes", 1, an object - yields default.
getInt
key. Returns default if the key is missing, the value is not numeric, has a fractional part, or does not fit in 32 bits - the latter two are also logged at warn, naming which of the two it was.
8 and 8.0 both read as 8: JSON has a single number type, so a whole number is one whether or not it was written with a decimal point. 8.5 does not read as 8 - a fractional value and an out-of-range one are both mismatches rather than something to truncate or saturate, because a wrong number returned as if it were the configured one cannot be detected by the caller. Use getLong for identifiers, amounts in minor units and nanosecond timestamps, and getDouble for a genuine fraction.
getLong
key as a Long, or default if the key is missing or the value is not an integer that fits in 64 bits.
This is the accessor that survives the JSON large-integer problem: the SDK keeps a JSON number as text until the caller names the type it wants, so 9007199254740993 is carried through exactly rather than being rounded on the way in.
getDouble
key. Returns default if the key is missing or the value is not a valid double.
getJson
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
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.
findFlag
null when the flag does not exist. getFlag collapses “absent” and “off” into one boolean, which is usually what a caller wants but leaves no way to report a missing flag; the OpenFeature provider uses this to report FLAG_NOT_FOUND.
syncedAt
200 OK or a 304 Not Modified.
getSecret
key from the in-memory snapshot.
Throws:
NexusPublicKeyException- when the client was created with a public key (wxp_…, browser/frontend, safe to expose)NexusServiceKindMismatchException- when the service is of kindfrontendNexusSecretNotFoundException- whenkeyis not present in the secrets snapshot
getSecretFilePath
key. Only available for secrets of type file.
The file is 0600 from creation, inside a per-client 0700 directory created on first use. It is removed by close(), or by a JVM shutdown hook if the application exits without calling it. The file name is a SHA-256 hash of both key and value, because the path reaches application logs, environment variables and process listings. See Caching behaviour.
Throws:
NexusPublicKeyException- when the client was created with a public key (wxp_…, browser/frontend, safe to expose)NexusServiceKindMismatchException- when the service is of kindfrontend; a path is the secret’s contents, so the same gate asgetSecretappliesNexusSecretNotFoundException- whenkeyis not a known file-type secret
setSecret
key. Sends POST /v1/secrets with a JSON body of {"key", "value", "type"}. On success the server responds with 201 Created. Requires a secret key (wxs_…, backend services).
Parameters:
key- the secret key to create or overwritevalue- the plaintext secret valuetype- the secret type; defaults to"text"
NexusPublicKeyException- when the client was created with a public key (wxp_…, browser/frontend, safe to expose)NexusUnauthorizedException- HTTP 401NexusBillingException- HTTP 402NexusNotFoundException- HTTP 404NexusRateLimitedException- HTTP 429 (non-quarantine rate limit on write endpoints)
deleteSecret
key. Sends DELETE /v1/secrets/:key. On success the server responds with 200 OK. Requires a secret key (wxs_…).
Throws:
NexusPublicKeyException- when the client was created with a public key (wxp_…, browser/frontend, safe to expose)NexusUnauthorizedException- HTTP 401NexusBillingException- HTTP 402NexusNotFoundException- HTTP 404NexusRateLimitedException- HTTP 429 (non-quarantine rate limit on write endpoints)
deleteSecretVersion
key. Sends DELETE /v1/secrets/:key?version=N. On success the server responds with 200 OK. Requires a secret key (wxs_…).
Parameters:
key- the secret keyversion- the version number to delete
NexusPublicKeyException- when the client was created with a public key (wxp_…, browser/frontend, safe to expose)NexusUnauthorizedException- HTTP 401NexusBillingException- HTTP 402NexusNotFoundException- HTTP 404NexusRateLimitedException- HTTP 429 (non-quarantine rate limit on write endpoints)
A/B evaluation
evaluateAB
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
GET /v1/sync. Uses ETag/If-None-Match to skip the response body when nothing has changed (304 Not Modified), which also resets the freshness stamp. Updates the in-memory snapshot atomically on success, serialised with any background refresh so responses cannot apply out of order.
Throws:
NexusClosedException- the client has been closedNexusUnauthorizedException- HTTP 401NexusBillingException- HTTP 402 (also backs the background refresh off for five minutes and callsobserver.onBillingOverdue())NexusForbiddenException- HTTP 403NexusNotFoundException- HTTP 404NexusQuarantinedException- HTTP 429 with a quarantine body, its deadline clamped to at most 24 hoursNexusRateLimitedException- HTTP 429 without oneNexusResponseTooLargeException- the body exceeded 8 MiB
Stream
connectStream
NexusClosedException on a closed client.
See SSE live updates.
disconnectStream
streamStatus to DISCONNECTED. Does not affect the background TTL sync or the HTTP client.
streamStatus
StateFlow that reflects the current stream connection state. Possible values:
Lifecycle
close
NexusClient implements AutoCloseable. close() cancels the internal coroutine scope (including the stream), closes both HTTP clients and the metadata client, closes the WIF credential source - releasing an AWS credentials provider’s IMDS client and refresh thread - and removes every file written for a file-type secret.
It is idempotent and final: a closed client raises NexusClosedException from sync(), connectStream() and the write methods, and streamStatus reads DISCONNECTED. Cached getters keep working, since they touch nothing that was released.
