@worktango/feature-flags-node
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

@worktango/feature-flags-node

A Node.js-specific feature flag management package for WorkTango applications, built on top of DevCycle and OpenFeature.

Installation

npm install @worktango/feature-flags-node

Usage

import {
  initializeFeatureFlagProvider,
  getBooleanFlagValue,
  getOpenFeatureClient,
} from '@worktango/feature-flags-node';

// Initialize with your DevCycle SDK key
await initializeFeatureFlagProvider({
  sdkKey: 'your-devcycle-sdk-key',
  options: {
    disableAutomaticEventLogging: true,
    configPollingIntervalMS: 5 * 1000,
    eventFlushIntervalMS: 1000,
  },
});

// Get boolean feature flag value with user context
const isEnabled = await getBooleanFlagValue('my-feature', false, userContext);

Setting User Context

import { getOpenFeatureClient } from '@worktango/feature-flags-node';

// Set user context for feature flag evaluation
// Note: Custom data should be placed under privateCustomData
const userContext = {
  user_id: 'user123',
  email: 'user@example.com',
  privateCustomData: {
    companyId: 123,
    isAdmin: true,
  },
};

const client = getOpenFeatureClient();
await client.setContext(userContext);

API Reference

Types

  • FeatureFlagConfig: Interface for feature flag configuration
    interface FeatureFlagConfig {
      sdkKey: string;
      options?: DevCycleOptionsLocalEnabled; // Optional DevCycle configuration
      strictMode?: boolean; // Optional: When enabled (default: false), will throw an error if the Feature Flag Provider/Client is not properly configured.
      // When disabled, will only log a warning if the Provider/Client is not correctly configured.
    }

Functions

  • initializeFeatureFlagProvider(config: FeatureFlagConfig): Initialize the feature flag provider with DevCycle
  • getBooleanFlagValue(flag: string, defaultValue: boolean, context?: FeatureFlagUser, options?: FlagEvaluationOptions): Get boolean feature flag value
  • getOpenFeatureClient(): Get the OpenFeature client for additional flag types (string, number)
  • getFeatureFlagProvider(): Get the DevCycle provider instance
  • getFeatureFlagClient(): Get the DevCycle client instance

Constants

  • ANONYMOUS_FEATURE_FLAG_USER: Default anonymous user context

Readme

Keywords

none

Package Sidebar

Install

npm i @worktango/feature-flags-node

Weekly Downloads

1,567

Version

0.3.1

License

none

Unpacked Size

446 kB

Total Files

21

Last publish

Collaborators

  • worktango