UNPKG

@flags-sdk/statsig

Version:

Statsig provider for the Flags SDK

74 lines (71 loc) 2.83 kB
export { getProviderData } from './provider/index.js'; import { Adapter } from 'flags'; import Statsig, { StatsigOptions, StatsigUser, DynamicConfig, Layer } from 'statsig-node-lite'; export { DynamicConfig, Layer, default as Statsig, StatsigOptions, StatsigUser } from 'statsig-node-lite'; type FeatureGate = ReturnType<typeof Statsig.getFeatureGateWithExposureLoggingDisabledSync>; type AdapterFunction<O> = <T>(getValue: (obj: O) => T, opts?: { exposureLogging?: boolean; }) => Adapter<T, StatsigUser>; type AdapterResponse = { featureGate: AdapterFunction<FeatureGate>; dynamicConfig: AdapterFunction<DynamicConfig>; experiment: AdapterFunction<DynamicConfig>; autotune: AdapterFunction<DynamicConfig>; layer: AdapterFunction<Layer>; initialize: () => Promise<typeof Statsig>; }; /** * Create a Statsig adapter for use with the Flags SDK. * * Can be used to define flags that are powered by Statsig's Feature Management * products including Feature Gates and Dynamic Configs. */ declare function createStatsigAdapter(options: { /** The Statsig server API key */ statsigServerApiKey: string; /** Optionally override Statsig initialization options */ statsigOptions?: StatsigOptions; /** Provide the project ID to allow links to the Statsig console in the Vercel Toolbar */ statsigProjectId?: string; /** Provide Edge Config details to use the optional Edge Config adapter */ edgeConfig?: { connectionString: string; itemKey: string; }; }): AdapterResponse; declare function resetDefaultStatsigAdapter(): void; /** * Equivalent to `createStatsigAdapter` but with default environment variable names. * * Required: * - `STATSIG_SERVER_API_KEY` - Statsig secret server API key * * Optional: * - `STATSIG_PROJECT_ID` - Statsig project ID to enable link in Vercel's Flags Explorer * - `EXPERIMENTATION_CONFIG` - Vercel Edge Config connection string * - `EXPERIMENTATION_CONFIG_ITEM_KEY` - Vercel Edge Config item key where data is stored */ declare function createDefaultStatsigAdapter(): AdapterResponse; /** * The default Statsig adapter. * * This is a convenience object that pre-initializes the Statsig SDK and provides * the adapter functions for the Feature Gates, Dynamic Configs, Experiments, * Autotunes, and Layers. * * This is the recommended way to use the Statsig adapter. * * ```ts * // flags.ts * import { flag } from 'flags/next'; * import { statsigAdapter } from '@flags-sdk/statsig'; * * const flag = flag({ * key: 'my-flag', * defaultValue: false, * adapter: statsigAdapter.featureGate((gate) => gate.value), * }); * ``` */ declare const statsigAdapter: AdapterResponse; export { type FeatureGate, createDefaultStatsigAdapter, createStatsigAdapter, resetDefaultStatsigAdapter, statsigAdapter };