> ## Documentation Index
> Fetch the complete documentation index at: https://docs.westyx.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenFeature integration

> Use NexusProvider to evaluate feature flags and configs via the OpenFeature standard interface.

> Requires `WestyxNexus.OpenFeature` v0.10.0 or later alongside `WestyxNexus`.

The `WestyxNexus.OpenFeature` package provides `NexusProvider`, an OpenFeature-compliant `FeatureProvider` that wraps an existing `NexusClient`. All evaluations are served from the client's local in-memory cache - no extra network calls are made per flag evaluation.

## Installation

```sh theme={null}
dotnet add package WestyxNexus.OpenFeature
```

Both `WestyxNexus` and `WestyxNexus.OpenFeature` must be installed. They are separate NuGet packages from the same GitLab registry.

## Quick start

```csharp theme={null}
using OpenFeature;
using Westyx.Nexus;
using Westyx.Nexus.OpenFeature;

// Create and start the Nexus client as usual.
await using var nexus = await NexusClient.CreateAsync(new NexusConfig
{
    BaseUrl = "https://blue-ocean-a5rx7.westyx.dev",
    ApiKey  = "wxs_...",
});
nexus.ConnectStream();   // recommended - keeps flags up to date over SSE

// Register the provider once, at startup.
await Api.Instance.SetProviderAsync(new NexusProvider(nexus));

// Evaluate flags anywhere via the OpenFeature client.
var client = Api.Instance.GetClient();
bool enabled = await client.GetBooleanValue("new.checkout", false);
```

## Value mapping

| OpenFeature type | OpenFeature method | Nexus source                                       |
| ---------------- | ------------------ | -------------------------------------------------- |
| Boolean          | `GetBooleanValue`  | `GetFlag(key, defaultValue)` - returns `is_active` |
| String           | `GetStringValue`   | `GetConfig(key)` - JSON string value               |
| Double           | `GetDoubleValue`   | `GetConfig(key)` - JSON number value               |
| Integer          | `GetIntegerValue`  | `GetConfig(key)` - JSON integer value              |
| Structure        | `GetObjectValue`   | `GetConfig(key)` - any JSON value                  |

**Flags vs configs:** Boolean resolution uses `GetFlag` (the feature flag cache). All other types use `GetConfig` (the config cache).

## Error handling

| Scenario                         | `ErrorType`    | `Reason`                           |
| -------------------------------- | -------------- | ---------------------------------- |
| Flag/config key not found        | `FlagNotFound` | `Default` (default value returned) |
| Config value has wrong JSON type | `TypeMismatch` | `Error` (default value returned)   |
| Successful evaluation            | `None`         | `Cached`                           |

The provider never throws; it always returns a `ResolutionDetails<T>` with the appropriate error type set.

## ASP.NET Core DI example

```csharp theme={null}
using OpenFeature;
using Westyx.Nexus;
using Westyx.Nexus.OpenFeature;

var builder = WebApplication.CreateBuilder(args);

// Register the Nexus client.
builder.Services.AddSingleton(sp =>
{
    var nexus = NexusClient.CreateAsync(new NexusConfig
    {
        BaseUrl = builder.Configuration["Nexus:BaseUrl"]!,
        ApiKey  = builder.Configuration["Nexus:ApiKey"]!,
    }).GetAwaiter().GetResult();
    nexus.ConnectStream();
    return nexus;
});

// Register the OpenFeature provider.
builder.Services.AddSingleton<NexusProvider>(sp =>
    new NexusProvider(sp.GetRequiredService<NexusClient>()));

// Register IFeatureClient for injection into services.
builder.Services.AddSingleton<IFeatureClient>(sp =>
{
    var provider = sp.GetRequiredService<NexusProvider>();
    Api.Instance.SetProviderAsync(provider).GetAwaiter().GetResult();
    return Api.Instance.GetClient();
});
```

Inject `IFeatureClient` into your services:

```csharp theme={null}
public class CheckoutService(IFeatureClient flags)
{
    public async Task<bool> IsNewCheckoutEnabled()
        => await flags.GetBooleanValue("new.checkout", false);
}
```

## Live updates

When `nexus.ConnectStream()` is active, the client's cache is updated within milliseconds of a remote flag change via SSE. OpenFeature evaluations pick up the new value on the next call because the provider reads directly from the live cache.
