configdn-openfeature-provider
v0.1.0
Published
OpenFeature provider for ConfigDN
Maintainers
Readme
ConfigDN OpenFeature Provider
An OpenFeature provider for the ConfigDN JavaScript client. The package supports both OpenFeature's client-side Web SDK and its server SDK through separate entry points.
Installation
Install the provider, ConfigDN client, and the OpenFeature SDK for the runtime you are using.
Browser, React, and other client-side applications:
npm install configdn-openfeature-provider @openfeature/web-sdk configdn-jsNode.js and other server-style applications:
npm install configdn-openfeature-provider @openfeature/server-sdk configdn-jsBrowser And React
Use ConfigDNProvider with @openfeature/web-sdk. The root import, /web, and /browser imports are equivalent.
import { OpenFeature } from "@openfeature/web-sdk";
import { ConfigDNProvider } from "configdn-openfeature-provider";
const provider = new ConfigDNProvider("YOUR_CONFIGDN_AUTH_KEY");
await OpenFeature.setProviderAndWait(provider);
const client = OpenFeature.getClient();
const enabled = await client.getBooleanValue("new-checkout", false);
const title = await client.getStringValue("checkout-title", "Checkout");The Web SDK provider resolves synchronously from the ConfigDN client cache. setProviderAndWait should be used so the initial ConfigDN refresh completes before the application evaluates flags.
Node.js And Server Runtimes
Use ConfigDNServerProvider with @openfeature/server-sdk. The /node and /server imports are equivalent.
import { OpenFeature } from "@openfeature/server-sdk";
import { ConfigDNServerProvider } from "configdn-openfeature-provider/node";
const provider = new ConfigDNServerProvider("YOUR_CONFIGDN_AUTH_KEY");
await OpenFeature.setProviderAndWait(provider);
const client = OpenFeature.getClient();
const enabled = await client.getBooleanValue("new-checkout", false);The server provider implements the asynchronous OpenFeature provider contract, but evaluations still use the already-loaded ConfigDN cache rather than making a network request for every evaluation.
Configuration
The constructor accepts the ConfigDN authorization key and optional client settings:
const provider = new ConfigDNProvider("YOUR_CONFIGDN_AUTH_KEY", {
endpoint: "https://your-configdn-server.example/",
refreshInterval: 60
});endpoint defaults to https://cdn.configdn.com/. refreshInterval is measured in seconds and defaults to 60.
Supported Values
The provider supports OpenFeature:
- Boolean values with
getBooleanValue. - String values with
getStringValue. - Number values with
getNumberValue. - JSON object and array values with
getObjectValue.
The default value must have the same type as the ConfigDN value. Missing keys, transport failures, and type mismatches return the supplied default value and include an OpenFeature error reason.
Entry Points
| Runtime | Import | Provider |
| --- | --- | --- |
| Browser, React | configdn-openfeature-provider | ConfigDNProvider |
| Browser | configdn-openfeature-provider/browser | ConfigDNProvider |
| Bun | configdn-openfeature-provider/bun | ConfigDNServerProvider |
| Node.js | configdn-openfeature-provider/node | ConfigDNServerProvider |
| Server-style runtimes | configdn-openfeature-provider/server | ConfigDNServerProvider |
| Deno | configdn-openfeature-provider/deno | ConfigDNServerProvider |
| Cloudflare Workers | configdn-openfeature-provider/cloudflare-worker | ConfigDNServerProvider |
| Chromium extensions | configdn-openfeature-provider/chromium-extension | ConfigDNProvider |
Each entry point is available as CommonJS and ESM and includes TypeScript declarations.
Lifecycle And Context
Call provider.shutdown() when the provider is no longer needed. This stops ConfigDN's refresh timer and aborts an active request.
ConfigDN currently stores and evaluates values without an OpenFeature user context. The context arguments are accepted to satisfy the provider contract but are not used for targeting.
The host runtime must provide fetch and AbortController. The provider does not bundle a fetch polyfill.
