New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@openfeature/flagd-provider

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openfeature/flagd-provider

This provider is designed to use flagd's [evaluation protocol](https://github.com/open-feature/schemas/blob/main/protobuf/schema/v1/schema.proto), or locally evaluate flags defined in a flagd [flag definition](https://github.com/open-feature/schemas/blob/

  • 0.11.1
  • npm
  • Socket score

Version published
Weekly downloads
4.4K
decreased by-14.72%
Maintainers
2
Weekly downloads
 
Created
Source

Server-Side flagd Provider

This provider is designed to use flagd's evaluation protocol, or locally evaluate flags defined in a flagd flag definition. This repository and package provides the client code for interacting with it via the OpenFeature server-side JavaScript SDK.

Installation

npm

npm install @openfeature/flagd-provider

yarn

yarn add @openfeature/server-sdk @grpc/grpc-js @openfeature/flagd-core

[!NOTE] yarn requires manual installation of peer dependencies

Configurations and Usage

The FlagdProvider supports multiple configuration options and has the ability to resolve flags remotely over RPC or in-process. Options can be defined in the constructor or as environment variables. Constructor options having the highest precedence.

Available Configuration Options

Option nameEnvironment variable nameTypeDefaultSupported values
hostFLAGD_HOSTstringlocalhost
portFLAGD_PORTnumber8013
tlsFLAGD_TLSbooleanfalse
socketPathFLAGD_SOCKET_PATHstring-
resolverTypeFLAGD_SOURCE_RESOLVERstringrpcrpc, in-process
offlineFlagSourcePathFLAGD_OFFLINE_FLAG_SOURCE_PATHstring-
selectorFLAGD_SOURCE_SELECTORstring-
cacheFLAGD_CACHEstringlrulru, disabled
maxCacheSizeFLAGD_MAX_CACHE_SIZEint1000

Below are examples of usage patterns.

Remote flag resolving over RPC

This is the default mode of operation of the provider. In this mode, FlagdProvider communicates with flagd via the gRPC protocol. Flag evaluations take place remotely on the connected flagd instance.

  OpenFeature.setProvider(new FlagdProvider())

In the above example, the provider expects flagd to be available at localhost:8013 (default host and port).

Alternatively, you can use socket paths to connect to flagd.

  OpenFeature.setProvider(new FlagdProvider({
      socketPath: "/tmp/flagd.socks",
  }))

In-process resolver

This mode performs flag evaluations locally (in-process). Flag configurations for evaluation are obtained via gRPC protocol using sync protobuf schema service definition.

  OpenFeature.setProvider(new FlagdProvider({
      resolverType: 'in-process',
  }))

In the above example, the provider expects a flag sync service implementation to be available at localhost:8013 (default host and port).

In-process resolver can also work in an offline mode. To enable this mode, you should provide a valid flag configuration file with the option offlineFlagSourcePath.

  OpenFeature.setProvider(new FlagdProvider({
      resolverType: 'in-process',
      offlineFlagSourcePath: './flags.json',
  }))

Offline mode uses fs.watchFile and polls every 5 seconds for changes to the file. This mode is useful for local development, test cases, and for offline applications.

Supported Events

The flagd provider emits PROVIDER_READY, PROVIDER_ERROR and PROVIDER_CONFIGURATION_CHANGED events.

SDK eventOriginating action in flagd
PROVIDER_READYThe streaming connection with flagd has been established.
PROVIDER_ERRORThe streaming connection with flagd has been broken.
PROVIDER_CONFIGURATION_CHANGEDA flag configuration (default value, targeting rule, etc) in flagd has changed.

For general information on events, see the official documentation.

Flag Metadata

FieldTypeValue
scopestring"selector" set for the associated source in flagd

Building

Run nx package providers-flagd to build the library.

NOTE: Buf must be installed to build locally.

Running Unit Tests

Run nx test providers-flagd to execute the unit tests via Jest.

FAQs

Package last updated on 15 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc