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

@hyphen/openfeature-server-provider

v1.0.1

Published

The official Hyphen Toggle OpenFeature Provider

Downloads

72

Readme

Hyphen Toggle OpenFeature Provider

The Hyphen Toggle OpenFeature Provider is an OpenFeature provider implementation for the Hyphen Toggle platform. It enables feature flag evaluation using the OpenFeature standard.


Table of Contents

  1. Getting Started
  2. Usage
  3. Configuration
  4. Contributing
  5. License

Getting Started

Installation

Install the provider and the OpenFeature server SDK:

npm install @openfeature/server-sdk @hyphen/openfeature-server-provider

Usage

Example: Basic Setup

To integrate the Hyphen Toggle provider into your application, follow these steps:

  1. Set up the provider: Register the HyphenProvider with OpenFeature using your publicKey and provider options.
  2. Evaluate a feature toggle: Use the client to evaluate a feature flag.
import { OpenFeature } from '@openfeature/server-sdk';
import { HyphenProvider, type HyphenProviderOptions } from '@hyphen/openfeature-server-provider';

const publicKey = "your-public-key-here";

const options: HyphenProviderOptions = {
application: 'your-application-name',
environment: 'production',
};

await OpenFeature.setProviderAndWait(new HyphenProvider(publicKey, options));

const client = OpenFeature.getClient();

const flagDetails = await client.getBooleanDetails('feature-flag-key', false);

console.log(flagDetails.value); // true or false

Example: Contextual Evaluation

To evaluate a feature flag with specific user or application context, define and pass an EvaluationContext:

const context: HyphenEvaluationContext = {
  targetingKey: 'user-123',
  ipAddress: '203.0.113.42',
  customAttributes: {
    subscriptionLevel: 'premium',
    region: 'us-east',
  },
  user: {
    id: 'user-123',
    email: '[email protected]',
    name: 'John Doe',
    customAttributes: {
      role: 'admin',
    },
  },
};

// Evaluate the toggle with context
const flagDetailsWithContext = await client.getBooleanDetails(toggleKey, defaultValue, context);

console.log(flagDetailsWithContext.value); // true or false

Configuration

Options

| Option | Type | Description | |---------------------|---------|---------------------------------------------------------------------------------------| | application | string | The application id or alternate id. | | environment | string | The environment in which your application is running (e.g., production, staging). | | enableToggleUsage | boolean | Enable or disable the logging of toggle usage (telemetry). | | cache | object | Configuration for caching feature flag evaluations. |

Cache Configuration

The cache option accepts the following properties:

| Property | Type | Default | Description | |----------------------|------------|---------|----------------------------------------------------------------| | ttlSeconds | number | 300 | Time-to-live in seconds for cached flag evaluations. | | generateCacheKeyFn | Function | - | Custom function to generate cache keys from evaluation context. |

Example with cache configuration:

const options: HyphenProviderOptions = {
  application: 'your-application-name',
  environment: 'production',
  cache: {
    ttlSeconds: 600, // 10 minutes
    generateCacheKeyFn: (context: HyphenEvaluationContext) => {
      return `${context.targetingKey}-${context.user?.id}`;
    },
  },
};

Context

Provide an EvaluationContext to pass contextual data for feature evaluation.

Context Fields

| Field | Type | Description | |---------------------|----------------------|-----------------------------------------------------------------------------| | targetingKey | string | The key used for caching the evaluation response. | | ipAddress | string | The IP address of the user making the request. | | customAttributes | Record<string, any> | Custom attributes for additional contextual information. | | user | object | An object containing user-specific information for the evaluation. | | user.id | string | The unique identifier of the user. | | user.email | string | The email address of the user. | | user.name | string | The name of the user. | | user.customAttributes | Record<string, any> | Custom attributes specific to the user. |

Contributing

We welcome contributions to this project! If you'd like to contribute, please follow the guidelines outlined in CONTRIBUTING.md. Whether it's reporting issues, suggesting new features, or submitting pull requests, your help is greatly appreciated!

License

This project is licensed under the MIT License. See the LICENSE file for full details.