npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devcycle/openfeature-nodejs-provider

v1.7.0

Published

OpenFeature Node Provider for DevCycle NodeJS SDK

Downloads

180

Readme

OpenFeature DevCycle NodeJS Provider

This library provides a NodeJS implementation of the OpenFeature Provider interface for DevCycle.

Building

Run nx build openfeature-nodejs-provider to build the library.

Running Unit Tests

Run nx test openfeature-nodejs-provider to execute the unit tests via Jest.

Example App

See the example app for a working example of the OpenFeature DevCycle NodeJS Provider.

Usage

See our documentation for more information.

import { OpenFeature, Client } from '@openfeature/server-sdk'
import { DevCycleProvider } from '@devcycle/openfeature-nodejs-provider'
import { initialize } from '@devcycle/nodejs-server-sdk'

... 

// Initialize the DevCycle SDK
const devcycleClient = await initializeDevCycle(DEVCYCLE_SERVER_SDK_KEY).onClientInitialized()
// Set the initialized DevCycle client as the provider for OpenFeature
OpenFeature.setProvider(new DevCycleProvider(devcycleClient))
// Get the OpenFeature client
openFeatureClient = OpenFeature.getClient()
// Set the context for the OpenFeature client, you can use 'targetingKey' or 'user_id'
openFeatureClient.setContext({ targetingKey: 'node_sdk_test' })


// Retrieve a boolean flag from the OpenFeature client
const boolFlag = await openFeatureClient.getBooleanValue('boolean-flag', false)

Passing DVCOptions to the DevCycleProvider

Ensure that you pass any custom DVCOptions to the DevCycleProvider constructor

const options = { logger: dvcDefaultLogger({ level: 'debug' }) }
const devcycleClient = await initializeDevCycle(DEVCYCLE_SERVER_SDK_KEY, options).onClientInitialized()
OpenFeature.setProvider(new DevCycleProvider(devcycleClient, options))

Required TargetingKey

For DevCycle SDK to work we require either a targetingKey or user_id to be set on the OpenFeature context. This is used to identify the user as the user_id for a DVCUser in DevCycle.

Context properties to DVCUser

The provider will automatically translate known DVCUser properties from the OpenFeature context to the DVCUser object. DVCUser TypeScript Interface

For example all these properties will be set on the DVCUser:

openFeatureClient.setContext({
    user_id: 'user_id',
    email: '[email protected]',
    name: 'name',
    language: 'en',
    country: 'CA',
    appVersion: '1.0.11',
    appBuild: 1000,
    customData: { custom: 'data' },
    privateCustomData: { private: 'data' }
})

Context properties that are not known DVCUser properties will be automatically added to the customData property of the DVCUser.

Context Limitations

DevCycle only supports flat JSON Object properties used in the Context. Non-flat properties will be ignored.

For example obj will be ignored:

openFeatureClient.setContext({
    user_id: 'user_id',
    obj: { key: 'value' }
})

JSON Flag Limitations

The OpenFeature spec for JSON flags allows for any type of valid JSON value to be set as the flag value.

For example the following are all valid default value types to use with OpenFeature:

// Invalid JSON values for the DevCycle SDK, will return defaults
openFeatureClient.getObjectValue('json-flag', ['arry'])
openFeatureClient.getObjectValue('json-flag', 610)
openFeatureClient.getObjectValue('json-flag', false)
openFeatureClient.getObjectValue('json-flag', 'string')
openFeatureClient.getObjectValue('json-flag', null)

However, these are not valid types for the DevCycle SDK, the DevCycle SDK only supports JSON Objects:

// Valid JSON Object as the default value, will be evaluated by the DevCycle SDK
openFeatureClient.getObjectValue('json-flag', { default: 'value' })