@happykit/flags
Version:
Feature Flags for Next.js
46 lines (42 loc) • 2 kB
TypeScript
import { Configuration } from './config.js';
import { I as Input, O as Outcome, F as Flags, a as FlagUser, T as Traits, d as InitialFlagState, e as FlagBag } from './types-06e22b20.js';
export { e as FlagBag, a as FlagUser, F as Flags, d as InitialFlagState, I as Input, O as Outcome, T as Traits } from './types-06e22b20.js';
import 'cookie';
declare class ObjectMap<Key extends any, Value extends any> {
keys: Key[];
values: Value[];
constructor();
private _getIndex;
set(key: Key, value: Value): void;
get<ReturnValue>(key: Key): ReturnValue | null;
/** Resets the cache. For testing purposes. */
clear(): void;
}
declare const cache: ObjectMap<Input, Outcome<Flags>>;
interface FactoryUseFlagOptions {
/**
* By default `@happykit/flags` refetches the feature flags when the window
* regains focus. You can disable this by passing `revalidateOnFocus: false`.
*/
revalidateOnFocus?: boolean;
/**
* A timeout in milliseconds after which any client-side evaluation requests
* from `useFlags` will be aborted.
*
* Pass `false` to disable this feature.
*
* This feature is only supported in [browsers which support](https://caniuse.com/abortcontroller) the [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
*/
clientLoadingTimeout?: number;
}
declare type UseFlagsOptions<F extends Flags = Flags> = ({
user?: FlagUser | null;
traits?: Traits | null;
initialState?: InitialFlagState<F>;
pause?: boolean;
} & FactoryUseFlagOptions) | undefined;
/**
* Creates a useFlags() function your application should use when loading flags on the client.
*/
declare function createUseFlags<F extends Flags>(configuration: Configuration<F>, { revalidateOnFocus: factoryRevalidateOnFocus, clientLoadingTimeout: factoryClientLoadingOptions, }?: FactoryUseFlagOptions): (options?: UseFlagsOptions<F>) => FlagBag<F>;
export { UseFlagsOptions, cache, createUseFlags };