@vercel/flags
Version:
Flags SDK by Vercel - The feature flags toolkit for Next.js and SvelteKit
43 lines (40 loc) • 1.51 kB
TypeScript
import { Handle } from '@sveltejs/kit';
import { f as FlagDeclaration, J as JsonValue, a as ApiData, G as GenerousOption } from './types-swW0-Ony.js';
import 'http';
import '@edge-runtime/cookies';
type Flag<ReturnValue> = (() => ReturnValue | Promise<ReturnValue>) & {
key: string;
description?: string;
origin?: string | Record<string, unknown>;
options?: GenerousOption<ReturnValue>[];
};
/**
* Declares a feature flag
*/
declare function flag<T>(definition: FlagDeclaration<T, unknown>): Flag<T>;
declare function getProviderData(flags: Record<string, Flag<JsonValue>>): ApiData;
/**
* Establishes context for flags, so they have access to the
* request and cookie.
*
* Also registers evaluated flags, except for flags used only after `resolve` calls in other handlers.
*
* @example Usage example in src/hooks.server.ts
*
* ```ts
* import { createHandle } from '@vercel/flags/sveltekit';
* import { FLAGS_SECRET } from '$env/static/private';
* import * as flags from '$lib/flags';
*
* export const handle = createHandle({ secret: FLAGS_SECRET, flags });
* ```
*
* @example Usage example in src/hooks.server.ts with other handlers
*
* Note that when composing `createHandle` with `sequence` then `createHandle` should come first. Only handlers after it will be able to access feature flags.
*/
declare function createHandle({ secret, flags, }: {
secret: string;
flags?: Record<string, Flag<JsonValue>>;
}): Handle;
export { createHandle, flag, getProviderData };