A Node.js-specific feature flag management package for WorkTango applications, built on top of DevCycle and OpenFeature.
npm install @worktango/feature-flags-nodeA Node.js-specific feature flag management package for WorkTango applications, built on top of DevCycle and OpenFeature.
``bash`
npm install @worktango/feature-flags-node
`typescript
import {
initializeFeatureFlagProvider,
getBooleanFlagValue,
getStringFlagValue,
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,
},
strictMode: true, // Optional: When enabled, will throw errors if not properly configured
});
// 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,
},
};
// Get boolean feature flag value with user context
const isEnabled = await getBooleanFlagValue('my-feature', false, userContext);
// Get string feature flag value with user context
const stringValue = await getStringFlagValue('my-feature', 'default-value', userContext);
`
You can also check how the flags are being evaluated by using our EXPERIMENTAL function.
Don't use this in prod code.
`typescript`
// Inside any function, but before the feature flag evaluation.
// The preference is for this to run a single time, so running on the server start,
// after the FeatureFlag provider started is the best place.
____experimental_featureFlagEvaluationHooks();
Example result:
`shell`
before hook {
user: DevCycleUser {
user_id: 'hey-ha-asdasd@no-pe.com',
email: 'yes-sha@some.com',
name: undefined,
language: undefined,
country: undefined,
appVersion: undefined,
appBuild: undefined,
customData: undefined,
privateCustomData: undefined
},
variableKey: 'example-feature-flag',
defaultValue: false,
metadata: {
project: { id: 'a0s98f09a8sf09a8sf09a8sfas9', key: 'test-project' },
environment: { id: 'a9sdg79as8d7ga9sd87ga9sd7', key: 'development' }
}
}
after hook {
user: DevCycleUser {
user_id: 'hey-ha-asdasd@no-pe.com',
email: 'yes-sha@some.com',
name: undefined,
language: undefined,
country: undefined,
appVersion: undefined,
appBuild: undefined,
customData: undefined,
privateCustomData: undefined
},
variableKey: 'example-feature-flag',
defaultValue: false,
metadata: {
project: { id: 'a0s98f09a8sf09a8sf09a8sfas9', key: 'test-project' },
environment: { id: 'a9sdg79as8d7ga9sd87ga9sd7', key: 'development' }
}
} DVCVariable {
key: 'example-feature-flag',
isDefaulted: false,
value: true,
defaultValue: false,
eval: {
reason: 'TARGETING_MATCH',
details: 'All Users',
target_id: 'fasf098a0s9f8a1kj414'
},
type: 'Boolean'
}
- FeatureFlagConfig: Interface for feature flag configuration`
typescript`
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.
}
- initializeFeatureFlagProvider(config: FeatureFlagConfig): Initialize the feature flag provider with DevCyclegetBooleanFlagValue(flag: string, defaultValue: boolean, context?: FeatureFlagUser, options?: FlagEvaluationOptions)
- : Get boolean feature flag valuegetStringFlagValue(flag: string, defaultValue: string, context?: FeatureFlagUser, options?: FlagEvaluationOptions)
- : Get string feature flag valuegetOpenFeatureClient()
- : Get the OpenFeature client for additional flag types (string, number)getFeatureFlagProvider()
- : Get the DevCycle provider instancegetFeatureFlagClient()
- : Get the DevCycle client instance____experimental_featureFlagEvaluationHooks
- : (Not final version, don't use it for prod code) Check how the flags are being evaluated.
- ANONYMOUS_FEATURE_FLAG_USER`: Default anonymous user context