### Example Setup with GrowthBook Client Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/growthbook-client/README.md Configure and set the GrowthBook Client Provider for OpenFeature. Ensure GrowthBook context and optional init options are correctly defined before setting the provider. ```typescript import { GrowthBook, Context, InitOptions } from '@growthbook/growthbook'; import { GrowthbookClientProvider } from '@openfeature/growthbook-client-provider'; /* * Configure your GrowthBook instance with GrowthBook context * @see https://docs.growthbook.io/lib/js#step-1-configure-your-app */ const gbContext: Context = { apiHost: 'https://cdn.growthbook.io', clientKey: 'sdk-abc123', // Only required if you have feature encryption enabled in GrowthBook decryptionKey: 'key_abc123', }; /* * optional init options * @see https://docs.growthbook.io/lib/js#switching-to-init */ const initOptions: InitOptions = { timeout: 2000, streaming: true, }; OpenFeature.setProvider(new GrowthbookClientProvider(gbContext, initOptions)); ``` -------------------------------- ### Install @openfeature/web-sdk Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Installs the experimental web SDK required for the flagd-web provider. ```bash npm install @openfeature/web-sdk ``` -------------------------------- ### Install flagd-web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Installs the flagd-web provider package. ```bash npm install @openfeature/flagd-web-provider ``` -------------------------------- ### Install Multi-Provider Package Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Install the Multi-Provider package using npm. ```bash npm install @openfeature/multi-provider ``` -------------------------------- ### Install GrowthBook Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/growthbook/README.md Install the GrowthBook provider using npm. ```bash npm install @openfeature/growthbook-provider ``` -------------------------------- ### Install LaunchDarkly Client Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/launchdarkly-client/README.md Install the LaunchDarkly client provider package using npm. ```bash npm install @openfeature/launchdarkly-client-provider ``` -------------------------------- ### Install Multi-Provider Web SDK Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Install the Multi-Provider package for the OpenFeature web SDK using npm. ```bash $ npm install @openfeature/multi-provider-web ``` -------------------------------- ### Install GrowthBook Client Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/growthbook-client/README.md Install the GrowthBook Client Provider package using npm. ```bash npm install @openfeature/growthbook-client-provider ``` -------------------------------- ### Initialize Multi-Provider with Providers Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Initialize the WebMultiProvider with an array of providers and set it as the OpenFeature provider. This example demonstrates basic setup for evaluating flags. ```typescript import { WebMultiProvider } from '@openfeature/multi-provider-web'; import { OpenFeature } from '@openfeature/web-sdk'; const multiProvider = new WebMultiProvider([{ provider: new ProviderA() }, { provider: new ProviderB() }]); await OpenFeature.setProviderAndWait(multiProvider); const client = OpenFeature.getClient(); console.log('Evaluating flag'); console.log(client.getBooleanDetails('my-flag', false)); ``` -------------------------------- ### Install go-feature-flag-web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag-web/README.md Install the necessary packages for the GO Feature Flag web provider and the OpenFeature web SDK using npm. ```shell npm install @openfeature/go-feature-flag-web-provider @openfeature/web-sdk ``` -------------------------------- ### Install Flipt Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt/README.md Install the Flipt provider package using npm. ```bash npm install @openfeature/flipt-provider ``` -------------------------------- ### Install Flipt Web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt-web/README.md Install the necessary packages for the OpenFeature web SDK and the Flipt web provider using npm. ```bash npm install @openfeature/web-sdk @openfeature/flipt-web-provider ``` -------------------------------- ### Install LocalStorage Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Install the LocalStorage Provider and its required peer dependency, the web SDK. ```bash $ npm install @openfeature/localstorage-provider $ npm install @openfeature/web-sdk ``` -------------------------------- ### Install Go Feature Flag Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Install the Go Feature Flag provider package using npm. Ensure the OpenFeature server SDK is also installed as a peer dependency. ```bash npm install @openfeature/go-feature-flag-provider ``` ```bash npm install @openfeature/server-sdk ``` -------------------------------- ### Install Unleash Web Provider and SDK Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/unleash-web/README.md Install the necessary packages for the Unleash web provider and the OpenFeature web SDK using npm. ```shell npm install @openfeature/unleash-web-provider @openfeature/web-sdk ``` -------------------------------- ### Install OFREP Provider with yarn Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Install the OFREP provider and its core dependencies using yarn. Note that yarn may require manual installation of peer dependencies. ```sh yarn add @openfeature/ofrep-provider @openfeature/ofrep-core @openfeature/server-sdk ``` -------------------------------- ### Install Environment Variable Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/env-var/README.md Install the environment variable provider package using npm. Also install the required server SDK peer dependency. ```bash npm install @openfeature/env-var-provider ``` ```bash npm install @openfeature/server-sdk ``` -------------------------------- ### Install Peer Dependencies for EventHook Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/open-telemetry/README.md Install the OpenTelemetry logs SDK if you are using the EventHook. ```bash npm install @opentelemetry/sdk-logs ``` -------------------------------- ### Build flagd-web Library Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Builds the flagd-web library using Nx. Requires Buf to be installed locally. ```bash npx nx package flagd-web ``` -------------------------------- ### Install flagd Provider via yarn Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd/README.md Install the flagd provider and its dependencies using yarn. Note that yarn may require manual installation of peer dependencies. ```sh yarn add @openfeature/server-sdk @grpc/grpc-js @openfeature/flagd-core ``` -------------------------------- ### Install OFREP Web Provider via yarn Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep-web/README.md Install the OFREP web provider and its core dependencies using yarn. Note that yarn may require manual installation of peer dependencies. ```sh yarn add @openfeature/ofrep-web-provider @openfeature/ofrep-core @openfeature/web-sdk @openfeature/core ``` -------------------------------- ### Install OFREP Provider with npm Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Install the OFREP provider package using npm. ```sh npm install @openfeature/ofrep-provider ``` -------------------------------- ### Basic OFREP Provider Setup Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep-web/README.md Instantiate and set the OFREP Web Provider with the base URL of the OFREP server. ```typescript import { OFREPWebProvider } from '@openfeature/ofrep-web-provider'; OpenFeature.setProvider(new OFREPWebProvider({ baseUrl: 'https://localhost:8080' })); ``` -------------------------------- ### Install ConfigCat Web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat-web/README.md Install the ConfigCat Web Provider and its required peer dependencies using npm. ```bash $ npm install @openfeature/config-cat-web-provider $ npm install @openfeature/web-sdk @configcat/sdk ``` -------------------------------- ### Install flagd Provider via npm Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd/README.md Install the flagd provider package using npm. This command installs the necessary package for integrating flagd with your OpenFeature SDK. ```sh npm install @openfeature/flagd-provider ``` -------------------------------- ### Install ConfigCat Provider and Dependencies Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/README.md Install the ConfigCat provider package along with its required peer dependencies, the OpenFeature SDK and the ConfigCat SDK. ```bash $ npm install @openfeature/config-cat-provider $ npm install @openfeature/server-sdk @configcat/sdk ``` -------------------------------- ### Install OpenTelemetry Hooks Package Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/open-telemetry/README.md Install the OpenTelemetry hooks package using npm. ```bash npm install @openfeature/open-telemetry-hooks ``` -------------------------------- ### Initialize FlagdCore and Set Configurations Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/shared/flagd-core/README.md Instantiate FlagdCore and provide valid flagd flag configurations using a string. This is the initial setup step before resolving flags. ```typescript const core = new FlagdCore(); core.setConfigurations(FLAG_CONFIGURATION_STRING); ``` -------------------------------- ### Basic Setup with Remote Evaluation Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Initialize the GoFeatureFlagProvider with a remote endpoint and register it with OpenFeature. This setup is suitable for applications requiring centralized flag management. ```typescript import { OpenFeature } from '@openfeature/server-sdk'; import { GoFeatureFlagProvider, EvaluationType } from '@openfeature/go-feature-flag-provider'; // Initialize the provider const provider = new GoFeatureFlagProvider({ endpoint: 'https://your-relay-proxy.com', evaluationType: EvaluationType.Remote, }); // Register the provider OpenFeature.setProvider(provider); // Get a client const client = OpenFeature.getClient(); // Evaluate a flag const flagValue = await client.getBooleanValue('my-feature-flag', false, { targetingKey: 'user-123', email: 'user@example.com', }); ``` -------------------------------- ### Install Flagsmith Provider and Dependencies Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith/README.md Install the Flagsmith provider along with the OpenFeature server SDK and the Flagsmith Node.js SDK. ```bash npm install @openfeature/flagsmith-provider @openfeature/server-sdk@^1.19 flagsmith-nodejs@^6.1 ``` -------------------------------- ### Install AWS SSM Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/aws-ssm/README.md Install the AWS SSM provider package using npm. ```bash npm install @openfeature/aws-ssm-provider ``` -------------------------------- ### Install Flagsmith OpenFeature Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith-client/README.md Install the provider using npm. Ensure SDK version compatibility with peerDependencies. ```bash npm install @openfeature/flagsmith-client-provider ``` -------------------------------- ### Install Peer Dependencies for Hooks Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/open-telemetry/README.md Install necessary peer dependencies for MetricsHook, SpanEventHook, or SpanHook. ```bash npm install @openfeature/core @opentelemetry/api ``` -------------------------------- ### Initialize OpenFeature with Flipt Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt-web/README.md Initialize the OpenFeature client with the FliptWebProvider, specifying the namespace and the Flipt server URL. Ensure to await the provider setup. ```typescript import { FliptWebProvider } from '@openfeature/flipt-web-provider'; const provider = new FliptWebProvider('namespace-of-choice', { url: 'http://your.upstream.flipt.host' }); await OpenFeature.setProviderAndWait(provider); ``` -------------------------------- ### In-Process Evaluation Setup Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Configure the GoFeatureFlagProvider for in-process evaluation to achieve high performance by evaluating flags locally. This setup allows for local caching and minimal network calls. ```typescript import { GoFeatureFlagProvider, EvaluationType } from '@openfeature/go-feature-flag-provider'; const provider = new GoFeatureFlagProvider({ endpoint: 'https://your-relay-proxy.com', evaluationType: EvaluationType.InProcess, flagChangePollingIntervalMs: 30000, // Poll every 30 seconds }); ``` -------------------------------- ### Install React Native Flagsmith SDK Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith-client/README.md Install the necessary packages for using Flagsmith with React Native and OpenFeature. ```bash npm install flagsmith react-native-flagsmith ``` -------------------------------- ### Install Debounce Hook Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/debounce/README.md Install the debounce hook package using npm. This package has a peer dependency on `@openfeature/core`. ```bash npm install @openfeature/debounce-hook ``` -------------------------------- ### Initialize ConfigCat Provider with Custom Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/README.md Configure the ConfigCat provider with a different polling mode and custom options, such as logging and hook setup. ```javascript import { OpenFeature } from '@openfeature/server-sdk'; import { ConfigCatProvider } from '@openfeature/config-cat-provider'; import { createConsoleLogger, LogLevel, PollingMode } from '@configcat/sdk'; // Create and set the provider. const provider = ConfigCatProvider.create('', PollingMode.LazyLoad, { logger: createConsoleLogger(LogLevel.Info), setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')) }); await OpenFeature.setProviderAndWait(provider); // ... ``` -------------------------------- ### Initialize Flagsmith Provider with Custom Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith/README.md Configure the Flagsmith client and the OpenFeature provider with custom options for advanced use cases. This example shows enabling local evaluation and setting retry counts. ```javascript import { OpenFeature } from '@openfeature/server-sdk'; import FlagsmithOpenFeatureProvider from '@openfeature/flagsmith-provider'; import Flagsmith from 'flagsmith-nodejs'; // Create the Flagsmith client with custom options const flagsmith = new Flagsmith({ environmentKey: '', enableLocalEvaluation: true, retries: 3, }); // Create the provider with custom configuration const provider = new FlagsmithOpenFeatureProvider(flagsmith, { returnValueForDisabledFlags: true, useFlagsmithDefaults: true, useBooleanConfigValue: false, }); await OpenFeature.setProviderAndWait(provider); // ... ``` -------------------------------- ### Get String Flag Value and Details Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Retrieve the string value of a feature flag or detailed evaluation information. ```typescript const message = await client.getStringValue('welcome-message', 'Hello!', context); const details = await client.getStringDetails('welcome-message', 'Hello!', context); ``` -------------------------------- ### Custom Tracking Strategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Implements a custom strategy to control which providers receive tracking calls. This example only tracks with the 'primary-provider' and skips 'analytics.' events on backup providers. ```typescript import { BaseEvaluationStrategy, StrategyPerProviderContext } from '@openfeature/multi-provider'; class CustomTrackingStrategy extends BaseEvaluationStrategy { shouldTrackWithThisProvider( strategyContext: StrategyPerProviderContext, context: EvaluationContext, trackingEventName: string, trackingEventDetails: TrackingEventDetails, ): boolean { // Only track with the primary provider if (strategyContext.providerName === 'primary-provider') { return true; } // Skip tracking for analytics events on backup providers if (trackingEventName.startsWith('analytics.')) { return false; } return super.shouldTrackWithThisProvider(strategyContext, context, trackingEventName, trackingEventDetails); } } ``` -------------------------------- ### Register Environment Variable Provider Globally Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/env-var/README.md Register the environment variable provider globally with the OpenFeature SDK to start using it. ```typescript // Register the environment variable provider globally OpenFeature.setProvider(new EnvVarProvider()); ``` -------------------------------- ### Custom Tracking Strategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Example of a custom strategy that overrides the `shouldTrackWithThisProvider` method to control which providers receive tracking calls. This allows for fine-grained control over event distribution. ```typescript import { BaseEvaluationStrategy, StrategyProviderContext } from '@openfeature/multi-provider-web'; class CustomTrackingStrategy extends BaseEvaluationStrategy { // Override tracking behavior shouldTrackWithThisProvider( strategyContext: StrategyProviderContext, context: EvaluationContext, trackingEventName: string, trackingEventDetails: TrackingEventDetails, ): boolean { // Only track with the primary provider if (strategyContext.providerName === 'primary-provider') { return true; } // Skip tracking for analytics events on backup providers if (trackingEventName.startsWith('analytics.')) { return false; } return super.shouldTrackWithThisProvider(strategyContext, context, trackingEventName, trackingEventDetails); } } ``` -------------------------------- ### Package and Verify Dependencies Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Run this command to package your module and then verify the dependencies listed in the generated package.json. Ensure the JS-SDK is correctly specified as a peer dependency. ```bash npm run package ``` -------------------------------- ### Initialize ConfigCat Provider with Default Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/README.md Set up the ConfigCat provider using the default configuration and an SDK key. After setting the provider, evaluate boolean feature flags. ```javascript import { OpenFeature } from '@openfeature/server-sdk'; import { ConfigCatProvider } from '@openfeature/config-cat-provider'; // Create and set the provider. const provider = ConfigCatProvider.create(''); await OpenFeature.setProviderAndWait(provider); // Obtain a client instance and evaluate feature flags. const client = OpenFeature.getClient(); const value = await client.getBooleanValue('isAwesomeFeatureEnabled', false); console.log(`isAwesomeFeatureEnabled: ${value}`); // On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. await OpenFeature.clearProviders(); ``` -------------------------------- ### Build Unleash Web Provider Library Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/unleash-web/README.md Build the Unleash web provider library using the nx package command. ```shell nx package providers-unleash-web ``` -------------------------------- ### Build the Flagsmith Provider Library Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith/README.md Run this command to build the Flagsmith provider package. Ensure you are in the project root. ```bash nx package providers-flagsmith ``` -------------------------------- ### Initialize Provider with Default Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat-web/README.md Create and set the ConfigCat provider using the default configuration. Ensure to clean up providers on application shutdown. ```javascript import { OpenFeature } from '@openfeature/web-sdk'; import { ConfigCatWebProvider } from '@openfeature/config-cat-web-provider'; // Create and set the provider. const provider = ConfigCatWebProvider.create(''); await OpenFeature.setProviderAndWait(provider); // Create a client instance to evaluate feature flags. const client = OpenFeature.getClient(); const value = await client.getBooleanValue('isAwesomeFeatureEnabled', false); console.log(`isAwesomeFeatureEnabled: ${value}`); // On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. await OpenFeature.clearProviders(); ``` -------------------------------- ### Configure and Initialize GrowthBook Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/growthbook/README.md Set up the GrowthBook provider with client options and optional initialization options for OpenFeature. Ensure your GrowthBook instance is configured with the necessary context. ```typescript import { GrowthBookClient, ClientOptions, InitOptions, } from '@growthbook/growthbook'; import { GrowthbookProvider } from '@openfeature/growthbook-provider'; import { OpenFeature } from '@openfeature/server-sdk'; /* * Configure your GrowthBook instance with GrowthBook context * @see https://docs.growthbook.io/lib/js#step-1-configure-your-app */ const gbClientOptions: ClientOptions = { apiHost: 'https://cdn.growthbook.io', clientKey: 'sdk-abc123', // Only required if you have feature encryption enabled in GrowthBook decryptionKey: 'key_abc123', }; /* * optional init options * @see https://docs.growthbook.io/lib/js#switching-to-init */ const initOptions: InitOptions = { timeout: 2000, streaming: true, }; OpenFeature.setProvider(new GrowthbookProvider(gbClientOptions, initOptions)); ``` -------------------------------- ### List Available Projects/Modules Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Execute this command to list all available projects or modules within the NX monorepo. This is useful for identifying module names for targeted testing. ```bash npx nx show projects ``` -------------------------------- ### Initialize Multi-Provider and Track Events Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Sets up the Multi-Provider with two underlying providers and demonstrates tracking an event. Tracked events are sent to all providers by default. ```typescript import { OpenFeature } from '@openfeature/server-sdk'; import { MultiProvider } from '@openfeature/multi-provider'; const multiProvider = new MultiProvider([{ provider: new ProviderA() }, { provider: new ProviderB() }]); await OpenFeature.setProviderAndWait(multiProvider); const client = OpenFeature.getClient(); // Tracked events will be sent to all providers by default client.track('purchase', { targetingKey: 'user123' }, { value: 99.99, currency: 'USD' }); ``` -------------------------------- ### Get Object Flag Value and Details Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Retrieve the object value of a feature flag or detailed evaluation information. ```typescript const config = await client.getObjectValue('user-config', {}, context); const details = await client.getObjectDetails('user-config', {}, context); ``` -------------------------------- ### Get Number Flag Value and Details Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Retrieve the number value of a feature flag or detailed evaluation information. ```typescript const percentage = await client.getNumberValue('discount-percentage', 0, context); const details = await client.getNumberDetails('discount-percentage', 0, context); ``` -------------------------------- ### Get Boolean Flag Value and Details Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Retrieve the boolean value of a feature flag or detailed evaluation information. ```typescript const isEnabled = await client.getBooleanValue('feature-flag', false, context); const details = await client.getBooleanDetails('feature-flag', false, context); ``` -------------------------------- ### Initialize OpenFeature with Flipt Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt/README.md Initialize the OpenFeature client with the Flipt provider, specifying the namespace and Flipt host URL. ```typescript import { FliptProvider } from '@openfeature/flipt'; const provider = new FliptProvider('namespace-of-choice', { url: 'http://your.upstream.flipt.host' }); OpenFeature.setProvider(provider); ``` -------------------------------- ### Initialize LaunchDarkly Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/launchdarkly-client/README.md Initialize the LaunchDarkly provider with an environment ID and optional configuration. The provider defaults to an anonymous context if none is set. ```typescript import { LaunchDarklyClientProvider } from '@openfeature/launchdarkly-client-provider'; // initialize provider const clientEnvKey = 'LDEnvironmentID'; /* * optional launch darkly options * @see https://launchdarkly.github.io/js-client-sdk/interfaces/LDOptions.html */ const ldOptions = { streaming: true, }; /* * initialization happens inside the provider, the initial context will be { anonymous: true } by default if there is not context set in Open Feature. * @see https://launchdarkly.github.io/js-client-sdk/interfaces/LDContextCommon.html#anonymous * you can change it using setContext. */ const ldOpenFeatureProvider = new LaunchDarklyClientProvider(clientEnvKey, ldOptions); //set open feature provider and get client OpenFeature.setProvider(ldOpenFeatureProvider); const client = OpenFeature.getClient('my-client'); //use client const boolValue = client.getBooleanValue('boolFlag', false); ``` -------------------------------- ### Test the Entire Project Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Run this command to execute all tests across the entire monorepo. Ensure all modules pass before merging changes. ```bash npm run test ``` -------------------------------- ### Get Object Value from LocalStorage Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Retrieve an object value for a given flag key using the OpenFeature client. A default value is provided if the flag is not found. ```typescript const client = OpenFeature.getClient(); client.getObjectValue('preferred-sdk', { name: 'OpenFeature' }); ``` -------------------------------- ### Evaluate String Flag with OpenFeature Client Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Use the OpenFeature client to get the string value of a feature flag, with a default value provided if the flag is not found or cannot be evaluated. ```typescript const client = OpenFeature.getClient(); client.getStringValue('welcome-message', 'hi'); ``` -------------------------------- ### Initialize and Use GO Feature Flag Web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag-web/README.md Set up the GO Feature Flag web provider with your endpoint and attach it to the OpenFeature SDK. The static evaluation context is set once using OpenFeature.setContext. ```typescript const evaluationCtx: EvaluationContext = { targetingKey: 'user-key', email: 'john.doe@gofeatureflag.org', name: 'John Doe', }; const goFeatureFlagWebProvider = new GoFeatureFlagWebProvider({ endpoint: endpoint, customHeadeers: { 'User-Agent': "my-app/1.0.0", }, // ... }, logger); await OpenFeature.setContext(evaluationCtx); // Set the static context for OpenFeature OpenFeature.setProvider(goFeatureFlagWebProvider); // Attach the provider to OpenFeature const client = await OpenFeature.getClient(); // You can now use the client to use your flags if(client.getBooleanValue('my-new-feature', false)){ //... } // You can add handlers to know what happen in the provider client.addHandler(ProviderEvents.Ready, () => { ... }); client.addHandler(ProviderEvents.Error, () => { //... }); client.addHandler(ProviderEvents.Stale, () => { //... }); client.addHandler(ProviderEvents.ConfigurationChanged, () => { //... }); ``` -------------------------------- ### Initialize Multi-Provider with Default Strategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Initialize the Multi-Provider with an array of providers and set it as the OpenFeature provider. The default strategy evaluates providers in order and returns the first successful result. ```typescript import { MultiProvider } from '@openfeature/multi-provider'; import { OpenFeature } from '@openfeature/server-sdk'; const multiProvider = new MultiProvider([{ provider: new ProviderA() }, { provider: new ProviderB() }]); await OpenFeature.setProviderAndWait(multiProvider); const client = OpenFeature.getClient(); console.log('Evaluating flag'); console.log(await client.getBooleanDetails('my-flag', false)); ``` -------------------------------- ### Evaluate Number Flag with OpenFeature Client Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Use the OpenFeature client to get the number value of a feature flag, with a default value provided if the flag is not found or cannot be evaluated. ```typescript const client = OpenFeature.getClient(); client.getNumberValue('difficulty-multiplier', 0); ``` -------------------------------- ### Evaluate Boolean Flag with OpenFeature Client Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Use the OpenFeature client to get the boolean value of a feature flag, with a default value provided if the flag is not found or cannot be evaluated. ```typescript const client = OpenFeature.getClient(); client.getBooleanValue('enable-new-feature', false); ``` -------------------------------- ### Initialize Provider with Custom Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat-web/README.md Create and set the ConfigCat provider with custom options, such as a logger and event hooks. The provider supports AutoPolling mode only. ```javascript import { OpenFeature } from '@openfeature/web-sdk'; import { ConfigCatWebProvider } from '@openfeature/config-cat-web-provider'; import { createConsoleLogger, LogLevel } from '@configcat/sdk'; // Create and set the provider. const provider = ConfigCatWebProvider.create('', { logger: createConsoleLogger(LogLevel.Info), setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')) }); await OpenFeature.setProviderAndWait(provider); // ... ``` -------------------------------- ### Set Evaluation Context and Evaluate Flags Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt-web/README.md Set the static evaluation context for OpenFeature, including targeting key and other properties. Then, get a client and evaluate feature flags. ```typescript const evaluationCtx: EvaluationContext = { targetingKey: 'myentity', email: 'john@flipt.io', }; // Set the static context for OpenFeature await OpenFeature.setContext(evaluationCtx); // Attach the provider to OpenFeature const client = await OpenFeature.getClient(); // You can now use the client to evaluate your flags const details = client.getStringDetails('my-feature', 'default'); ``` -------------------------------- ### Initialize Flagsmith Provider with Default Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith/README.md Set up the Flagsmith provider using default configurations and evaluate a boolean feature flag. Remember to clean up providers on application shutdown. ```javascript import { OpenFeature } from '@openfeature/server-sdk'; import { FlagsmithOpenFeatureProvider } from '@openfeature/flagsmith-provider'; import { Flagsmith } from 'flagsmith-nodejs'; // Create the Flagsmith client const flagsmith = new Flagsmith({ environmentKey: '', }); // Create and set the provider const provider = new FlagsmithOpenFeatureProvider(flagsmith); await OpenFeature.setProviderAndWait(provider); // Obtain a client instance and evaluate feature flags const client = OpenFeature.getClient(); const value = await client.getBooleanValue('my-flag', false, { targetingKey: 'user-123' }); console.log(`my-flag: ${value}`); // On application shutdown, clean up the OpenFeature provider await OpenFeature.clearProviders(); ``` -------------------------------- ### Initialize Multi-Provider with FirstSuccessfulStrategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Initialize the Multi-Provider with a custom strategy, FirstSuccessfulStrategy, which returns the first successful result and skips any provider that returns an error. ```typescript import { MultiProvider, FirstSuccessfulStrategy } from '@openfeature/multi-provider'; const multiProvider = new MultiProvider( [{ provider: new ProviderA() }, { provider: new ProviderB() }], new FirstSuccessfulStrategy(), ); ``` -------------------------------- ### Configure Multi-Provider with FirstSuccessfulStrategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Initialize the WebMultiProvider with a custom strategy, FirstSuccessfulStrategy, to control how providers are evaluated. This strategy returns the first successful result and skips any provider that returns an error. ```typescript import { WebMultiProvider, FirstSuccessfulStrategy } from '@openfeature/multi-provider-web'; const multiProvider = new WebMultiProvider( [{ provider: new ProviderA() }, { provider: new ProviderB() }], new FirstSuccessfulStrategy(), ); ``` -------------------------------- ### Basic Multi-Provider Tracking Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Demonstrates how to set up a Multi-Provider and use its basic tracking functionality. Tracked events are sent to all configured providers by default. ```typescript import { WebMultiProvider } from '@openfeature/multi-provider-web'; import { OpenFeature } from '@openfeature/web-sdk'; const multiProvider = new WebMultiProvider([{ provider: new ProviderA() }, { provider: new ProviderB() }]); await OpenFeature.setProviderAndWait(multiProvider); const client = OpenFeature.getClient(); // Tracked events will be sent to all providers by default client.track('user-conversion', { value: 99.99, currency: 'USD', conversionType: 'purchase', }); client.track('page-view', { page: '/checkout', source: 'direct', }); ``` -------------------------------- ### Configure OFREPProvider using Environment Variables Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Set environment variables to configure the OFREP provider with default settings for endpoint, timeout, and headers. Explicitly provided options will override these environment variables. ```bash export OFREP_ENDPOINT=http://localhost:2321 export OFREP_TIMEOUT_MS=5000 export OFREP_HEADERS=Authentication=Bearer 123,Content-Type=json ``` -------------------------------- ### OpenFeature Context to Flipt Context Transformation Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt/README.md Illustrates how an OpenFeature evaluation context, including a targetingKey and additional properties, is transformed into the format expected by Flipt. ```json { "entityId": "my-targeting-id", "context": { "email": "john@flipt.io", "userId": "this-very-long-user-id" } } ``` -------------------------------- ### Generate a Provider Module with NX Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Use this command to generate a new provider module within the monorepo. It sets up the basic code scaffolding and publishing infrastructure. ```bash npm run generate-provider ``` -------------------------------- ### Initialize Multi-Provider with ComparisonStrategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider/README.md Initialize the Multi-Provider with ComparisonStrategy for parallel evaluation. It returns a value if all providers agree, otherwise it uses a fallback provider and optionally executes a callback on mismatch. ```typescript import { MultiProvider, ComparisonStrategy } from '@openfeature/multi-provider'; const providerA = new ProviderA(); const multiProvider = new MultiProvider( [{ provider: providerA }, { provider: new ProviderB() }], new ComparisonStrategy(providerA, (details) => { console.log('Mismatch detected', details); }), ); ``` -------------------------------- ### Flipt Evaluation Context Transformation Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flipt-web/README.md Demonstrates how an OpenFeature evaluation context is transformed into the structure expected by Flipt, mapping 'targetingKey' to 'entityId' and other properties to 'context'. ```json { "targetingKey": "my-targeting-id", "email": "john@flipt.io", "userId": "this-very-long-user-id" } ``` ```json { "entityId": "my-targeting-id", "context": { "email": "john@flipt.io", "userId": "this-very-long-user-id" } } ``` -------------------------------- ### Configure Multi-Provider with ComparisonStrategy Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/multi-provider-web/README.md Initialize the WebMultiProvider with the ComparisonStrategy for parallel provider evaluation. This strategy returns a result only if all providers agree, otherwise it falls back to a specified provider and optionally executes a callback on mismatch. ```typescript import { WebMultiProvider, ComparisonStrategy } from '@openfeature/multi-provider-web'; const providerA = new ProviderA(); const multiProvider = new WebMultiProvider( [{ provider: providerA }, { provider: new ProviderB() }], new ComparisonStrategy(providerA, (details) => { console.log('Mismatch detected', details); }), ); ``` -------------------------------- ### Initialize Unleash Provider without Context Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/unleash-web/README.md Initialize the OpenFeature client with the UnleashWebProvider, specifying the Unleash instance URL, client key, and application name. Ensure OpenFeature is set to wait for the provider to be ready. ```typescript import { UnleashWebProvider } from '@openfeature/unleash-web-provider'; const provider = new UnleashWebProvider({ url: 'http://your.upstream.unleash.instance', clientKey: 'theclientkey', appName: 'your app', }); await OpenFeature.setProviderAndWait(provider); ``` -------------------------------- ### Configure OFREPProvider with Static Headers (Map) Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Provide static HTTP headers as a map for the OFREP provider. This offers an alternative way to specify fixed headers. ```typescript import { OFREPProvider } from '@openfeature/ofrep-provider'; OpenFeature.setProvider( new OFREPProvider({ baseUrl: 'https://localhost:8080', headers: { Authorization: `my-api-key`, 'X-My-Header': `CustomHeaderValue` }, }), ); ``` -------------------------------- ### Run Unit Tests for Unleash Web Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/unleash-web/README.md Execute the unit tests for the Unleash web provider using the nx test command, which utilizes Jest for testing. ```shell nx test providers-unleash-web ``` -------------------------------- ### Run Unit Tests Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Executes unit tests for the flagd-web package using Jest. ```bash npx nx test flagd-web ``` -------------------------------- ### Configure OFREPProvider with Static Headers (Array of Tuples) Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Provide static HTTP headers as an array of tuples for the OFREP provider. This is useful for setting fixed headers like API keys. ```typescript import { OFREPProvider } from '@openfeature/ofrep-provider'; OpenFeature.setProvider( new OFREPProvider({ baseUrl: 'https://localhost:8080', headers: [ ['Authorization', `my-api-key`], ['X-My-Header', `CustomHeaderValue`], ], }), ); ``` -------------------------------- ### Instantiate OFREPProvider with Base URL Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Set the OFREP provider for OpenFeature by providing the base URL of the OFREP server during instantiation. ```typescript import { OFREPProvider } from '@openfeature/ofrep-provider'; OpenFeature.setProvider(new OFREPProvider({ baseUrl: 'https://localhost:8080' })); ``` -------------------------------- ### Configure OFREPProvider with Custom Fetch Implementation Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Inject a custom fetch implementation into the OFREP provider. This is necessary for platforms that lack a built-in fetch API or when using a specific fetch polyfill. ```typescript import { OFREPProvider } from '@openfeature/ofrep-provider'; import { fetchPolyfill } from 'some-fetch-polyfill'; OpenFeature.setProvider( new OFREPProvider({ baseUrl: 'https://localhost:8080', fetchImplementation: fetchPolyfill, }), ); ``` -------------------------------- ### Initialize Unleash Provider with Context Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/unleash-web/README.md Initialize the UnleashWebProvider with a predefined Unleash context, including user ID, session ID, remote address, and custom properties. This context will be used for feature flag evaluations. ```typescript import { UnleashWebProvider } from '@openfeature/unleash-web-provider'; const context = { userId: '123', sessionId: '456', remoteAddress: 'address', properties: { property1: 'property1', property2: 'property2', }, }; const provider = new UnleashWebProvider({ url: 'http://your.upstream.unleash.instance', clientKey: 'theclientkey', appName: 'your app', context: context, }); await OpenFeature.setProviderAndWait(provider); ``` -------------------------------- ### Configure Static Headers (Map) Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep-web/README.md Set static HTTP headers for the OFREP provider using a map. ```typescript import { OFREPWebProvider } from '@openfeature/ofrep-web-provider'; OpenFeature.setProvider( new OFREPWebProvider({ baseUrl: 'https://localhost:8080', headers: { Authorization: `my-api-key`, 'X-My-Header': `CustomHeaderValue` }, }), ); ``` -------------------------------- ### Generate a Hook Module with NX Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Use this command to generate a new hook module within the monorepo. It sets up the basic code scaffolding and publishing infrastructure. ```bash npm run generate-hook ``` -------------------------------- ### Test a Single Module Source: https://github.com/open-feature/js-sdk-contrib/blob/main/CONTRIBUTING.md Use this command to test a specific module within the monorepo. Replace {MODULE NAME} with the actual name of the module you want to test. ```bash npx nx test {MODULE NAME} ``` -------------------------------- ### Initialize Flagsmith Provider in JavaScript Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith-client/README.md Initialize the Flagsmith OpenFeature provider with your client-side environment key and configure caching options. Then, set it as the OpenFeature provider. ```javascript import { FlagsmithClientProvider } from '@openfeature/flagsmith-client-provider'; import { OpenFeature } from '@openfeature/web-sdk'; const flagsmithClientProvider = new FlagsmithClientProvider({ environmentID: 'your_client_side_environment_key', cacheFlags: true, cacheOptions: { skipAPI: true, }, }); OpenFeature.setProvider(flagsmithClientProvider); ``` -------------------------------- ### Set Selector via Environment Variable Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd/README.md Sets the flagd selector using an environment variable, which is applied to the provider configuration. ```bash export FLAGD_SOURCE_SELECTOR="flagSetId=app-flags" ``` -------------------------------- ### Set flagd-web Provider with Options Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Configures and sets the flagd-web provider for OpenFeature, specifying connection details and retry behavior. Ensure the host and port match your flagd instance. ```typescript OpenFeature.setProvider( new FlagdWebProvider({ host: 'myapp.com', port: 443, tls: true, maxRetries: 10, maxDelay: 30000, }), ); ``` -------------------------------- ### ConfigCat User Object Representation Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/README.md Shows the resulting ConfigCat User object after mapping from an OpenFeature evaluation context, including custom attributes. ```json { "identifier": "userId", "email": "email", "country": "country", "custom": { "targetingKey": "userId", "customString": "customString", "customBoolean": "true", "customNumber": 1, "customObject": "{\"prop1\":\"1\",\"prop2\":2}", "customStringArray": ["one", "two"], "customArray": "[1,\"2\",false]" } } ``` -------------------------------- ### Run copy-latest-wasm.js Script Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/scripts/README.md Execute the `copy-latest-wasm.js` script manually to copy the go-feature-flag WASM evaluation module. This script is also automatically run by project targets. ```bash node scripts/copy-latest-wasm.js ``` -------------------------------- ### Configure Caching Options Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep-web/README.md Set caching options for the OFREP Web Provider, including cache mode, TTL, and a prefix for the cache key. ```typescript import { OFREPWebProvider } from '@openfeature/ofrep-web-provider'; OpenFeature.setProvider( new OFREPWebProvider({ baseUrl: 'https://localhost:8080', cacheMode: 'local-cache-first', cacheTTL: 3600, // 1 hour cacheKeyPrefix: 'my-app', }), ); ``` -------------------------------- ### Configure OFREPProvider with Header Factory Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep/README.md Use a header factory function to dynamically generate HTTP headers before each flag evaluation. This is useful for including time-sensitive or user-specific information like bearer tokens. ```typescript import { OFREPProvider } from '@openfeature/ofrep-provider'; OpenFeature.setProvider( new OFREPProvider({ baseUrl: 'https://localhost:8080', headersFactory: () => { const token: string = loadDynamicToken(); return [['Authorization', `Bearer ${token}`]]; }, }), ); ``` -------------------------------- ### Run Unit Tests for Flagsmith Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith/README.md Execute the unit tests for the Flagsmith provider using Jest. This command runs tests via the nx package manager. ```bash npx nx run providers-flagsmith:test ``` -------------------------------- ### Track Custom Events Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/launchdarkly-client/README.md Send custom events to LaunchDarkly metrics for experiments and rollouts. Ensure you have retrieved a client instance first. ```typescript const client = await OpenFeature.getClient(); client.track('event-key-123abc', { customProperty: someValue }); ``` -------------------------------- ### Register LocalStorage Provider with MultiProvider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Register the localStorage provider globally, using MultiProvider to allow it to override flag resolutions from other providers. ```typescript import { OpenFeature, MultiProvider } from '@openfeature/web-sdk'; import { LocalStorageProvider } from '@openfeature/localstorage-provider'; // Register the localStorage provider globally, using MultiProvider to allow it to override flag resolutions from other providers OpenFeature.setProvider( new MultiProvider([{ provider: new LocalStorageProvider() }, { provider: new OtherProvider() }]), ); ``` -------------------------------- ### OpenFeature Evaluation Context to ConfigCat User Mapping Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/config-cat/README.md Illustrates how OpenFeature evaluation context fields are mapped to ConfigCat User object attributes, including custom attributes. ```json { "targetingKey": "userId", "email": "email", "country": "country", "customString": "customString", "customNumber": 1, "customBoolean": true, "customObject": { "prop1": "1", "prop2": 2 }, "customStringArray": ["one", "two"], "customArray": [1, "2", false] } ``` -------------------------------- ### Configure Header Factory for Dynamic Headers Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/ofrep-web/README.md Use a header factory to dynamically generate HTTP headers, such as a bearer token, before each flag evaluation. ```typescript import { OFREPWebProvider } from '@openfeature/ofrep-web-provider'; OpenFeature.setProvider( new OFREPWebProvider({ baseUrl: 'https://localhost:8080', headersFactory: () => { const token: string = loadDynamicToken(); return [['Authorization', `Bearer ${token}`]]; }, }), ); ``` -------------------------------- ### Set String Flag via localStorage or Provider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Set a string feature flag by adding an entry to localStorage or using the provider's setFlags method. The provider then evaluates this flag. ```javascript // In the browser's developer console set a localStorage entry for the flag localStorage.setItem('openfeature.welcome-message', 'yo'); // Or, using the provider's setFlags method provider.setFlags({ 'welcome-message': 'yo' }); ``` -------------------------------- ### Basic Debounce Hook Usage Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/hooks/debounce/README.md Wrap a logging hook with the DebounceHook, configuring a debounce time of 60 seconds and a cache size of 100 items. Add the hook globally or to a specific client. ```typescript const debounceHook = new DebounceHook(loggingHook, { debounceTime: 60_000, // how long to wait before the hook can fire again maxCacheItems: 100, // max amount of items to keep in the cache; if exceeded, the oldest item is dropped }); // add the hook globally OpenFeature.addHooks(debounceHook); // or at a specific client client.addHooks(debounceHook); ``` -------------------------------- ### Specify Custom WASM Binary Path Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/go-feature-flag/README.md Provide a custom path for the WASM binary when using in-process evaluation, useful for custom bundling. ```typescript const provider = new GoFeatureFlagProvider({ endpoint: 'https://your-relay-proxy.com', evaluationType: EvaluationType.InProcess, wasmBinaryPath: '/path/to/custom/gofeatureflag-evaluation.wasm', }); ``` -------------------------------- ### Subscribe to Provider Ready Event Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd-web/README.md Subscribes to the ProviderEvents.Ready event to perform actions when the configuration has changed. This utilizes the event API in the web SDK for real-time flag value change subscriptions. ```typescript client.addHandler(ProviderEvents.Ready, () => { // do something when the configuration has changed. }); ``` -------------------------------- ### Set Provider with Selector (RPC Mode) Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd/README.md Configures the FlagdProvider with a selector to filter flag configurations for evaluation in RPC mode. ```typescript OpenFeature.setProvider( new FlagdProvider({ selector: 'flagSetId=payment-flags', }), ); ``` -------------------------------- ### Set AWS SSM Provider Configuration Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/aws-ssm/README.md Configure and set the AWS SSM provider for OpenFeature. Specify AWS region and optional caching settings for performance. ```typescript OpenFeature.setProvider( new AwsSsmProvider({ ssmClientConfig: { region: 'eu-west-1', // Change this to your desired AWS region // You can setup your aws credentials here or it will be automatically retrieved from env vars // See https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html }, // Use an LRUCache for improve performance and optimize AWS SDK Calls to SSM (cost awareness) cacheOpts: { enabled: true, // Enable caching size: 1, // Cache size ttl: 10, // Time-to-live in seconds }, }) ); ``` -------------------------------- ### Initialize Flagsmith Provider with React Native Instance Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagsmith-client/README.md Initialize the Flagsmith OpenFeature provider, passing the flagsmith instance obtained from 'react-native-flagsmith'. ```javascript import flagsmith from 'react-native-flagsmith'; import { FlagsmithClientProvider } from '@openfeature/flagsmith-client-provider'; import { OpenFeature } from '@openfeature/web-sdk'; const flagsmithClientProvider = new FlagsmithClientProvider({ environmentID: 'your_client_side_environment_key', flagsmithInstance: flagsmith, }); OpenFeature.setProvider(flagsmithClientProvider); ``` -------------------------------- ### Set Provider with Selector (In-Process Mode) Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/flagd/README.md Configures the FlagdProvider with a selector for filtering flag configurations in in-process mode. ```typescript OpenFeature.setProvider( new FlagdProvider({ resolverType: 'in-process', selector: 'flagSetId=app-flags', }), ); ``` -------------------------------- ### Set String Feature Flag via Environment Variable Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/env-var/README.md Set a string feature flag by exporting an environment variable before running your application. The client retrieves the string value. ```bash # Start a hypothetical application with the WELCOME_MESSAGE environment variable WELCOME_MESSAGE=yo node my-app.js ``` ```typescript const client = OpenFeature.getClient(); client.getStringValue('welcome-message', 'hi'); ``` -------------------------------- ### Set Multiple Flags with LocalStorageProvider Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Use the setFlags method to set multiple feature flags at once. The provider automatically adds the configured prefix to the keys. To remove a flag, set its value to undefined. ```typescript const provider = new LocalStorageProvider(); OpenFeature.setProvider(provider); // Pass an object with flag keys and values to set multiple flags at once // The provider will automatically add the prefix from the options to the keys when setting the values in localStorage provider.setFlags({ 'new-feature': true, 'difficulty-multiplier': 5, 'welcome-message': 'yo', 'preferred-sdk': { name: 'openfeature' }, }); // To remove a flag, set its value to `undefined` explicitly using the `setFlags` method provider.setFlags({ 'new-feature': undefined }); ``` -------------------------------- ### Set LocalStorage Flag Source: https://github.com/open-feature/js-sdk-contrib/blob/main/libs/providers/localstorage/README.md Set a localStorage entry for the flag in the browser's developer console. Alternatively, use the provider's setFlags method to achieve the same. ```javascript localStorage.setItem('openfeature.preferred-sdk', '{"name": "openfeature"}'); ``` ```javascript provider.setFlags({ 'preferred-sdk': { name: 'openfeature' } }); ```