flags
Version:
Flags SDK by Vercel - The feature flags toolkit for Next.js and SvelteKit
90 lines (82 loc) • 4.6 kB
TypeScript
import { TracerProvider } from '@opentelemetry/api';
import { P as ProviderData } from './types-CGpl9epN.js';
export { A as Adapter, a as ApiData, D as Decide, f as FlagDeclaration, b as FlagDefinitionType, c as FlagDefinitionsType, F as FlagOptionType, e as FlagOverridesType, d as FlagValuesType, G as GenerousOption, H as HeadersAdapter, I as Identify, J as JsonValue, O as Origin, R as ReadonlyHeaders, g as ReadonlyRequestCookies, h as RequestCookiesAdapter } from './types-CGpl9epN.js';
import 'http';
import '@edge-runtime/cookies';
/**
* Allows setting the `@opentelemetry/api` tracer provider to generate traces
* for `flags` operations.
*/
declare function setTracerProvider(tracer: TracerProvider): void;
/**
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
*
* This function is just like JSON.stringify but also escapes the resulting string to prevent XSS.
*
* @see https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer A function that transforms the results.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
declare function safeJsonStringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
/**
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
*
* This function is just like JSON.stringify but also escapes the resulting string to prevent XSS.
*
* @see https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
declare function safeJsonStringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
/**
* Function to encrypt overrides, values, definitions, and API data.
*/
declare function encrypt<T extends object>(value: T, secret?: string | undefined): Promise<string>;
/**
* Function to decrypt overrides, values, definitions, and API data.
*/
declare function decrypt<T extends object>(encryptedData: string, secret?: string | undefined): Promise<T | undefined>;
/**
* This function lets you verify whether a request to your application's .well-known/vercel/flags endpoint was made by the toolbar.
* You can use verifyAccess to keep this endpoint private, to avoid public access of your feature flag definitions through that endpoint.
*
* @example Using verifyAccess in .well-known/vercel/flags to verify access and respond with unencrypted data.
* ```
* import { type NextRequest, NextResponse } from "next/server";
* import { verifyAccess } from "flags";
*
* export async function GET(request: NextRequest) {
* const access = await verifyAccess(request.headers.get("Authorization"));
* if (!access) return NextResponse.json(null, { status: 401 });
*
* return NextResponse.json({ definitions: {} })
* }
* ```
* @param authHeader the Authorization header to check
* @param secret the FLAGS_SECRET
* @returns True when the authorization header was valid
*/
declare const verifyAccess: (authHeader: string | null | undefined, secret?: string | undefined) => Promise<boolean>;
/**
* This function lets you report the value of a resolved flag, which will make it available when viewing Monitoring, Logs, Analytics and Speed Insights on Vercel.
* It's important to note that this only has effects when running on Vercel in a preview or production environments, but not during local development.
*
* @example Using `reportValue` to report a flag value.
* ```
* import { type NextRequest, NextResponse } from "next/server";
* import { reportValue } from 'flags';
*
* export async function GET(request: NextRequest) {
* reportValue('my-flag', true);
* return NextResponse.json({});
* }
* ```
*
* @param key the name of the flag
* @param value the resolved value of the flag
*/
declare function reportValue(key: string, value: unknown): void;
declare function mergeProviderData(itemsPromises: (Promise<ProviderData> | ProviderData)[]): Promise<ProviderData>;
export { ProviderData, decrypt, encrypt, mergeProviderData, reportValue, safeJsonStringify, setTracerProvider, verifyAccess };