### Start Svelte development server Source: https://github.com/vercel/flags/blob/main/tests/sveltekit-e2e/README.md Run this command after installing dependencies to start the development server. The `-- --open` flag will automatically open the application in your default browser. ```bash npm run dev ``` ```bash npm run dev -- --open ``` -------------------------------- ### Initialize and Run Vercel Project Source: https://github.com/vercel/flags/blob/main/examples/shirt-shop/README.md Commands to link a local project to Vercel, synchronize environment variables, install dependencies, and start the development server. ```bash vercel link vercel env pull npm install npm run dev ``` -------------------------------- ### Install GrowthBook SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the GrowthBook SDK package using pnpm. ```bash pnpm i @flags-sdk/growthbook ``` -------------------------------- ### Install OpenFeature Provider Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/index.mdx Install the OpenFeature adapter and the OpenFeature Node.js SDK using npm. Ensure both packages are installed to use the adapter. ```bash npm i @flags-sdk/openfeature @openfeature/server-sdk ``` -------------------------------- ### Install Hypertune SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the Hypertune SDK and its dependencies using pnpm. ```bash pnpm i hypertune flags server-only @flags-sdk/hypertune @vercel/edge-config ``` -------------------------------- ### Install OpenFeature SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the OpenFeature adapter and the OpenFeature server SDK using pnpm. ```bash pnpm i @flags-sdk/openfeature @openfeature/server-sdk ``` -------------------------------- ### Install LaunchDarkly SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the LaunchDarkly provider package using pnpm. ```bash pnpm i @flags-sdk/launchdarkly ``` -------------------------------- ### Install the package Source: https://github.com/vercel/flags/blob/main/packages/flags/README.md Install the package using your package manager. ```sh npm install flags ``` -------------------------------- ### Install PostHog SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the PostHog provider package using pnpm. ```bash pnpm i @flags-sdk/posthog ``` -------------------------------- ### Install @vercel/prepare-flags-definitions Source: https://github.com/vercel/flags/blob/main/packages/prepare-flags-definitions/README.md Install the package using npm. This is typically done as a dev dependency. ```bash npm i @vercel/prepare-flags-definitions ``` -------------------------------- ### Install @flags-sdk/vercel Source: https://github.com/vercel/flags/blob/main/packages/adapter-vercel/README.md Install the necessary packages for the Vercel adapter. ```bash npm i flags @flags-sdk/vercel ``` -------------------------------- ### Install @flags-sdk/edge-config Source: https://github.com/vercel/flags/blob/main/packages/adapter-edge-config/README.md Install the package using npm. ```bash npm install @flags-sdk/edge-config ``` -------------------------------- ### Install Hypertune Adapter Source: https://github.com/vercel/flags/blob/main/packages/adapter-hypertune/README.md Command to install the Hypertune adapter package using pnpm. ```bash pnpm i @flags-sdk/hypertune ``` -------------------------------- ### Install Split and OpenFeature dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/split.mdx Install the necessary packages for the Flags SDK, OpenFeature, and the Split provider to enable integration. ```bash npm install flags @flags-sdk/openfeature @splitsoftware/openfeature-js-split-provider @openfeature/js-sdk @splitsoftware/splitio ``` -------------------------------- ### Install Statsig SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the Statsig SDK package using pnpm. ```bash pnpm i @flags-sdk/statsig ``` -------------------------------- ### Install Flags SDK Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/next/index.mdx Install the Flags SDK using npm. For AI coding assistants, install the Vercel Flags SDK agent skill. ```sh npm install flags ``` ```sh npx skills add vercel/flags --skill flags-sdk ``` -------------------------------- ### Install GrowthBook Provider Source: https://github.com/vercel/flags/blob/main/packages/adapter-growthbook/README.md Command to install the GrowthBook adapter module for the Flags SDK using pnpm. ```bash pnpm i @flags-sdk/growthbook ``` -------------------------------- ### Create and Set Up SvelteKit Project Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Scaffold a new SvelteKit project with TypeScript and Prettier, then start the development server. ```bash npx sv create sveltekit-flags-example cd sveltekit-flags-example npm run dev ``` -------------------------------- ### Install Tggl and Flags SDK dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/tggl.mdx Install the necessary packages for the Flags SDK, the OpenFeature adapter, and the Tggl provider using npm. ```bash npm install flags @flags-sdk/openfeature openfeature-server-tggl-provider ``` -------------------------------- ### Install Vercel Toolbar Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/nextjs.md Install the Vercel Toolbar SDK. ```sh pnpm i @vercel/toolbar ``` -------------------------------- ### Install Vercel Adapter Package Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/vercel.mdx Install the necessary packages for the Flags SDK and the Vercel adapter. ```bash pnpm i flags @flags-sdk/vercel ``` -------------------------------- ### Install Hypertune and Flags SDK dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/hypertune.mdx Install the necessary packages to enable Hypertune integration with the Flags SDK and OpenFeature. ```bash npm install flags @flags-sdk/openfeature @hypertune/openfeature-server-provider ``` -------------------------------- ### Install Reflag SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the Reflag SDK using pnpm. Ensure the REFLAG_SECRET_KEY environment variable is set. ```bash pnpm i @flags-sdk/reflag ``` -------------------------------- ### Install Flagsmith SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Install the Flagsmith SDK package using pnpm. ```bash pnpm i @flags-sdk/flagsmith ``` -------------------------------- ### Install Flags SDK Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/nextjs.md Install the Flags SDK using pnpm. ```sh pnpm i flags ``` -------------------------------- ### Install GrowthBook and OpenFeature Dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/growthbook.mdx Command to install the necessary packages for integrating GrowthBook with the Flags SDK using OpenFeature. ```bash npm install flags @flags-sdk/openfeature @growthbook/growthbook @openfeature/growthbook-provider ``` -------------------------------- ### Install Flags Package Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Install the flags package using npm. If using an AI coding assistant, install the Flags SDK agent skill. ```sh npm i flags ``` ```sh npx skills add vercel/flags --skill flags-sdk ``` -------------------------------- ### Install Confidence by Spotify dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/confidence-by-spotify.mdx Install the necessary packages for the Flags SDK, OpenFeature integration, and the Confidence by Spotify provider using npm. ```bash npm install flags @flags-sdk/openfeature @spotify-confidence/openfeature-server-provider ``` -------------------------------- ### Install Vercel CLI Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Install the latest version of the Vercel CLI globally using npm. ```bash npm i -g vercel@latest ``` -------------------------------- ### LaunchDarkly Usage Example Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Example of how to configure and use the LaunchDarkly adapter for feature flags. Requires setting up an identify function to provide user context. ```typescript import { ldAdapter, type LDContext } from '@flags-sdk/launchdarkly'; const identify = dedupe((async ({ headers, cookies }) => { const user = await getUser(headers, cookies); return { key: user.userID }; }) satisfies Identify); export const exampleFlag = flag({ key: 'example-flag', identify, adapter: ldAdapter.variation(), }); ``` -------------------------------- ### Install GrowthBook Adapter Package Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/growthbook.mdx Installs the GrowthBook adapter package using npm. This is the first step to integrate GrowthBook with the Flags SDK. ```bash npm install @flags-sdk/growthbook ``` -------------------------------- ### Run Development Server Source: https://github.com/vercel/flags/blob/main/apps/playground/README.md Execute this command to start the development server for the flags-playground application. Open http://localhost:3000 in your browser to see the changes. ```bash pnpm dev ``` -------------------------------- ### Core Library Usage Source: https://github.com/vercel/flags/blob/main/packages/vercel-flags-core/README.md Demonstrates how to install and use the core evaluation client from @vercel/flags-core. ```APIDOC ## Installation ```bash npm i @vercel/flags-core ``` ## Usage ### Description Initialize the Vercel Flags core client and evaluate a feature flag. ### Method N/A (Client Initialization and Evaluation) ### Endpoint N/A ### Parameters N/A ### Request Example ```ts import { createClient } from '@vercel/flags-core'; const client = createClient(process.env.FLAGS!); // Replace with your actual flags configuration await client.initialize(); const result = await client.evaluate('show-new-feature', false, { user: { id: 'user-123' }, }); ``` ### Response #### Success Response (200) N/A (Evaluation result is returned directly) #### Response Example ```json { "value": true, // or false, depending on flag configuration "reason": "TARGET" } ``` ``` -------------------------------- ### Install LaunchDarkly Provider Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/launchdarkly.mdx Installs the LaunchDarkly provider package using npm. This is the first step to integrating LaunchDarkly feature flags. ```bash npm install @flags-sdk/launchdarkly ``` -------------------------------- ### Install Edge Config Adapter Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/edge-config.mdx Install the Edge Config adapter for the Flags SDK using pnpm. ```sh pnpm i @flags-sdk/edge-config ``` -------------------------------- ### Install ConfigCat OpenFeature Dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/configcat.mdx Install the necessary packages to enable ConfigCat support via the OpenFeature adapter in your project. ```bash npm install flags @flags-sdk/openfeature @openfeature/config-cat-provider ``` -------------------------------- ### Start Next.js 16 Development Server Source: https://github.com/vercel/flags/blob/main/tests/README.md Command to start the Next.js 16 development server locally. This is typically run in a separate terminal to facilitate e2e testing. ```bash pnpm next-16 ``` -------------------------------- ### Install Vercel Flags and Toolbar Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/sveltekit.md Installs the necessary packages for Vercel Flags and the Vercel Toolbar using pnpm. ```sh pnpm i flags @vercel/toolbar ``` -------------------------------- ### Install @vercel/flags-core Source: https://github.com/vercel/flags/blob/main/packages/vercel-flags-core/README.md Installs the @vercel/flags-core package using npm. This is the first step to using the Vercel Flags evaluation engine. ```bash npm i @vercel/flags-core ``` -------------------------------- ### Install Dependencies for Hypertune Flags SDK Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/hypertune.mdx Installs the necessary packages for using the Hypertune provider with the Flags SDK. This includes hypertune, flags, server-only, @flags-sdk/hypertune, and @vercel/edge-config. ```bash pnpm i hypertune flags server-only @flags-sdk/hypertune @vercel/edge-config ``` -------------------------------- ### Install Flags SDK and FeatBit Packages Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/featbit.mdx Installs the necessary npm packages for integrating the Flags SDK with FeatBit's OpenFeature provider. This includes the core Flags SDK, the OpenFeature adapter, and FeatBit's Node.js SDKs. ```bash npm install flags @flags-sdk/openfeature @featbit/node-server-sdk @featbit/openfeature-provider-node-server ``` -------------------------------- ### Install Kameloon and OpenFeature dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/kameloon.mdx Installs the necessary npm packages to enable Kameloon support within the Flags SDK framework. ```bash npm install flags @flags-sdk/openfeature @kameleoon/openfeature-server ``` -------------------------------- ### Install PostHog OpenFeature dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/posthog.mdx Installs the core Flags SDK, the OpenFeature adapter, and the specific PostHog provider package via npm. ```bash npm install flags @flags-sdk/openfeature @tapico/node-openfeature-posthog ``` -------------------------------- ### Install Statsig Provider Source: https://github.com/vercel/flags/blob/main/packages/adapter-statsig/README.md Installs the Statsig provider module for the Flags SDK using pnpm. This is the first step to integrate Statsig features. ```bash pnpm i @flags-sdk/statsig ``` -------------------------------- ### Install LaunchDarkly Provider for Flags SDK Source: https://github.com/vercel/flags/blob/main/packages/adapter-launchdarkly/README.md Installs the LaunchDarkly provider package for the Flags SDK using npm. This is the first step to integrate LaunchDarkly feature flags into your project. ```bash npm i @flags-sdk/launchdarkly ``` -------------------------------- ### OpenFeature Sync Provider Setup Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Set up the OpenFeature adapter for a synchronous provider. This involves setting the provider and creating the adapter client. ```typescript import { createOpenFeatureAdapter } from '@flags-sdk/openfeature'; // Sync provider OpenFeature.setProvider(new YourProvider()); const adapter = createOpenFeatureAdapter(OpenFeature.getClient()); ``` -------------------------------- ### OpenFeature Async Provider Setup Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Set up the OpenFeature adapter for an asynchronous provider. This ensures the provider is ready before creating the adapter client. ```typescript const adapter = createOpenFeatureAdapter(async () => { await OpenFeature.setProviderAndWait(new YourProvider()); return OpenFeature.getClient(); }); ``` -------------------------------- ### Install Flags SDK and AB Tasty Provider Packages Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/abtasty.mdx Installs the necessary npm packages for integrating the Flags SDK with OpenFeature and the AB Tasty provider. This includes the core Flags SDK, its OpenFeature adapter, and the AB Tasty OpenFeature provider. ```bash npm install flags @flags-sdk/openfeature @flagship-io/openfeature-provider-js ``` -------------------------------- ### Install Flags SDK and OpenFeature Packages Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/flagd.mdx Installs the necessary npm packages for integrating the Flags SDK with OpenFeature and the flagd provider. This includes the core flags package, the OpenFeature adapter, and the flagd provider itself. ```bash npm install flags @flags-sdk/openfeature @openfeature/flagd-provider ``` -------------------------------- ### Build and Test Local Adapter Changes Source: https://github.com/vercel/flags/blob/main/docs/REVIEWS.md This sequence of commands outlines the process for building a local adapter package and testing it with an example project. It involves navigating to the adapter directory, building it, and then modifying a project's dependencies to point to the local build. ```bash cd packages/adapter-hypertune pnpm build ``` ```bash pnpm install vc link vc env pull # Modify @flags-sdk/launchdarkly to a relative path in package.json pnpm install ``` -------------------------------- ### PostHog Multivariate Feature Flag Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/providers.md Example of using the PostHog adapter to get the value of a multivariate feature flag. Requires an identify function for user context. ```typescript import { postHogAdapter } from '@flags-sdk/posthog'; // Multivariate value export const myVariant = flag({ key: 'my-flag', adapter: postHogAdapter.featureFlagValue(), identify, }); ``` -------------------------------- ### Basic Flagsmith Usage with Type Coercion Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/flagsmith.mdx Demonstrates how to use the Flagsmith adapter to get flag values with optional type coercion. It shows examples for raw values, strings, numbers, and booleans. ```typescript import { flag } from "flags/next"; import { flagsmithAdapter } from "@flags-sdk/flagsmith"; // No coercion - returns the raw value from Flagsmith export const rawFlag = flag({ key: "raw-value", defaultValue: "default", adapter: flagsmithAdapter.getValue(), }); // Coerce to string type export const buttonColor = flag({ key: "button-color", defaultValue: "blue", adapter: flagsmithAdapter.getValue({ coerce: "string" }), }); // Coerce to number type export const maxItems = flag({ key: "max-items", defaultValue: 10, adapter: flagsmithAdapter.getValue({ coerce: "number" }), }); // Coerce to boolean type export const showBanner = flag({ key: "show-banner", defaultValue: false, adapter: flagsmithAdapter.getValue({ coerce: "boolean" }), }); ``` -------------------------------- ### Create Custom LaunchDarkly Adapter Instance Source: https://github.com/vercel/flags/blob/main/packages/adapter-launchdarkly/README.md Shows how to create a custom LaunchDarkly adapter instance using the `createLaunchDarklyAdapter` function. This allows for explicit configuration of project slug, client-side key, and Edge Config connection string. ```typescript import { createLaunchDarklyAdapter } from "@flags-sdk/launchdarkly"; const adapter = createLaunchDarklyAdapter({ projectSlug: "my-project", ldClientSideKey: "612376f91b8f5713a58777a1", edgeConfigConnectionString: process.env.EDGE_CONFIG, }); ``` -------------------------------- ### Initialize Hypertune Adapter Source: https://github.com/vercel/flags/blob/main/packages/adapter-hypertune/README.md How to create and configure a Hypertune adapter instance using generated code and context identification. ```APIDOC ## Initialize Hypertune Adapter ### Description Initializes the Hypertune adapter for use within a Vercel/Next.js application, linking generated flag definitions with user context. ### Method N/A (Library Initialization) ### Parameters #### Request Body - **createSource** (Function) - Required - The source generator from Hypertune. - **flagFallbacks** (Object) - Required - Default values for flags. - **flagDefinitions** (Object) - Required - Generated flag definitions. - **identify** (Function) - Required - A function to resolve the user context (e.g., environment, user ID). ### Request Example ```ts const hypertuneAdapter = createHypertuneAdapter({ createSource, flagFallbacks, flagDefinitions, identify, }); ``` ### Response - **hypertuneAdapter** (Object) - An instance containing flag declarations ready for use in the application. ``` -------------------------------- ### Start Next.js Development Server Source: https://github.com/vercel/flags/blob/main/examples/snippets/README.md Commands to initiate the local development environment for a Next.js application. Supports multiple package managers including npm, yarn, pnpm, and bun. ```bash npm run dev yarn dev pnpm dev bun dev ``` -------------------------------- ### Install Reflag SDK Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/reflag.mdx Command to install the Reflag provider package for the Vercel Flags SDK. ```bash npm install @flags-sdk/reflag ``` -------------------------------- ### Install Reflag Provider Source: https://github.com/vercel/flags/blob/main/packages/adapter-reflag/README.md Command to install the Reflag provider package using the pnpm package manager. ```bash pnpm i @flags-sdk/reflag ``` -------------------------------- ### Install Statsig Provider Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/statsig.mdx Installs the Statsig provider package using npm. This is the first step to integrating Statsig with your application. ```bash npm install @flags-sdk/statsig ``` -------------------------------- ### Configure LaunchDarkly Environment Variables Source: https://github.com/vercel/flags/blob/main/packages/adapter-launchdarkly/README.md Sets up the necessary environment variables for the LaunchDarkly adapter. These include the client-side ID, project slug, and the Edge Config connection string provided by Vercel. ```bash export LAUNCHDARKLY_CLIENT_SIDE_ID="612376f91b8f5713a58777a1" export LAUNCHDARKLY_PROJECT_SLUG="my-project" # Provided by Vercel when connecting an Edge Config to the project export EDGE_CONFIG="https://edge-config.vercel.com/ecfg_abdc1234?token=xxx-xxx-xxx" ``` -------------------------------- ### Create Custom LaunchDarkly Adapter Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/launchdarkly.mdx Creates a customized LaunchDarkly adapter instance using `createLaunchDarklyAdapter`. This allows for explicit configuration of project slug, client-side ID, and edge config connection string via environment variables. ```typescript import { createLaunchDarklyAdapter } from '@flags-sdk/launchdarkly'; const customLdAdapter = createLaunchDarklyAdapter({ projectSlug: process.env.LAUNCHDARKLY_PROJECT_SLUG, clientSideId: process.env.LAUNCHDARKLY_CLIENT_SIDE_ID, edgeConfigConnectionString: process.env.EDGE_CONFIG, }); ``` -------------------------------- ### Create a new Svelte project Source: https://github.com/vercel/flags/blob/main/tests/sveltekit-e2e/README.md Use this command to initialize a new Svelte project. It can be run in the current directory or a specified directory name. ```bash npm create svelte@latest ``` ```bash npm create svelte@latest my-app ``` -------------------------------- ### Install GO FeatureFlag dependencies Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/go.mdx Install the required npm packages to integrate GO FeatureFlag with the Flags SDK and OpenFeature. ```bash npm install flags @flags-sdk/openfeature @openfeature/go-feature-flag-provider ``` -------------------------------- ### Setup DevCycle OpenFeature Adapter Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/devcycle.mdx Configures the OpenFeature adapter to use the DevCycle provider. This involves importing necessary modules, initializing the DevCycleProvider with your SDK key, setting it as the OpenFeature provider, and returning the OpenFeature client. ```typescript import { OpenFeature, } from "@openfeature/server-sdk"; import { createOpenFeatureAdapter, } from "@flags-sdk/openfeature"; import { DevCycleProvider, } from "@devcycle/nodejs-server-sdk"; export const openFeatureAdapter = createOpenFeatureAdapter(async () => { const provider = new DevCycleProvider(process.env.DEVCYCLE_SERVER_SDK_KEY); await OpenFeature.setProviderAndWait(provider); return OpenFeature.getClient(); }); ``` -------------------------------- ### Initialize GrowthBook Adapter Source: https://github.com/vercel/flags/blob/main/packages/adapter-growthbook/README.md Importing the default adapter instance from the GrowthBook package. ```typescript import { growthBookAdapter } from "@flags-sdk/growthbook"; ``` -------------------------------- ### Install Flagsmith Provider Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/flagsmith.mdx Installs the Flagsmith provider module using npm. This is the first step to integrate Flagsmith with the Flags SDK. ```bash npm i @flags-sdk/flagsmith ``` -------------------------------- ### Inline Statsig Bootstrap Data on Server Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/statsig.mdx Demonstrates how to identify the user, initialize the Statsig adapter, and generate a client-side initialization response on the server. This data is then passed to a client component provider. ```tsx import { cookies, headers } from "next/headers"; import { statsigAdapter } from "@flags-sdk/statsig"; import { DynamicStatsigProvider } from "./dynamic-statsig-provider"; import { identify } from "../../identify"; export default async function Layout({ children, }: { children: React.ReactNode; }) { const [headersStore, cookieStore] = await Promise.all([headers(), cookies()]); const user = await identify({ headers: headersStore, cookies: cookieStore }); const Statsig = await statsigAdapter.initialize(); const datafile = await Statsig.getClientInitializeResponse(user, { hash: "djb2", }); return ( {children} ); } ``` -------------------------------- ### Install Vercel Toolbar Package Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Install the Vercel Toolbar package using npm. This is the first step to enable toolbar functionality in your project. ```sh npm i @vercel/toolbar ``` -------------------------------- ### Initialize Custom PostHog Adapter Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/posthog.mdx Shows how to manually initialize the PostHog adapter with specific configuration options instead of relying on default environment variables. ```ts import { createPostHogAdapter } from '@flags-sdk/posthog' const postHogAdapter = createPostHogAdapter({ postHogKey: process.env.NEXT_PUBLIC_POSTHOG_KEY, postHogOptions: { host: process.env.NEXT_PUBLIC_POSTHOG_HOST, }, }) ``` -------------------------------- ### Run Svelte Development Server Source: https://github.com/vercel/flags/blob/main/examples/sveltekit-example/README.md Commands to start the development server for a Svelte project. The --open flag will automatically open the application in a new browser tab. ```bash npm run dev ``` ```bash npm run dev -- --open ``` -------------------------------- ### Example: Using LaunchDarkly Adapter for Feature Flag Source: https://github.com/vercel/flags/blob/main/packages/adapter-launchdarkly/README.md Demonstrates how to use the LaunchDarkly adapter with the Flags SDK to manage a boolean feature flag named 'show-banner'. It includes defining an identify function for user context and configuring the flag with the `ldAdapter`. ```typescript import { flag, dedupe } from "flags/next"; import { ldAdapter, type LDContext } from "@flags-sdk/launchdarkly"; const identify = dedupe(async (): Promise => { return { key: "user_123", }; }); export const showBanner = flag({ key: "show-banner", identify, adapter: ldAdapter.variation(), }); ``` -------------------------------- ### Manually Initialize LaunchDarkly Client Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/launchdarkly.mdx Provides an example of manually calling `waitForInitialization()` on the LaunchDarkly client. This ensures the client is ready before the first flag evaluation, which can be useful in server-side code. ```typescript import { ldAdapter } from '@flags-sdk/launchdarkly'; // Somewhere in your server-side code await ldAdapter.ldClient.waitForInitialization(); ``` -------------------------------- ### Install PostHog Adapter for Flags SDK Source: https://github.com/vercel/flags/blob/main/packages/adapter-posthog/README.md Installs the PostHog adapter package for the Flags SDK using pnpm. This is the first step to integrate PostHog feature flags. ```bash pnpm i @flags-sdk/posthog ``` -------------------------------- ### Create OpenFeature Adapter for Async Providers Source: https://github.com/vercel/flags/blob/main/packages/adapter-openfeature/README.md Shows how to create an OpenFeature adapter instance for asynchronous providers. This involves passing an initialization function that sets up the provider and returns the client asynchronously. ```typescript import { createOpenFeatureAdapter } from "@flags-sdk/openfeature"; // pass an init function, and return the client const openFeatureAdapter = createOpenFeatureAdapter(async () => { const provider = new YourProviderOfChoice(); await OpenFeature.setProviderAndWait(provider); return OpenFeature.getClient(); }); ``` -------------------------------- ### Install Packages for Flipt OpenFeature Integration Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/flipt.mdx Installs the necessary npm packages for integrating the Flags SDK with OpenFeature and the Flipt provider. This includes the core flags package, the OpenFeature adapter, and the Flipt provider itself. ```bash npm install flags @flags-sdk/openfeature @openfeature/flipt-provider ``` -------------------------------- ### Install DevCycle and Flags SDK Packages Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/devcycle.mdx Installs the necessary npm packages for integrating DevCycle with the Flags SDK and OpenFeature. This includes the core flags package, the OpenFeature adapter, and the DevCycle Node.js server SDK. ```bash npm install flags @flags-sdk/openfeature @devcycle/nodejs-server-sdk ``` -------------------------------- ### Implement Redis Sticky Bucketing Source: https://github.com/vercel/flags/blob/main/packages/adapter-growthbook/README.md Configuring sticky bucketing for GrowthBook experiments using a Redis service to ensure consistent user experience across sessions. ```typescript import { RedisStickyBucketService } from "@growthbook/growthbook"; import Redis from "ioredis"; const redis = new Redis(process.env.REDIS_CONNECTION_URL); const redisStickyBucketService = new RedisStickyBucketService({ redis }); growthbookAdapter.setStickyBucketService(redisStickyBucketService); ``` -------------------------------- ### Install Flags SDK and CloudBees Provider Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/openfeature/cloudbees.mdx Installs the necessary npm packages for integrating the Flags SDK with CloudBees using OpenFeature. This includes the core Flags SDK, the OpenFeature adapter, and the CloudBees OpenFeature provider. ```bash npm install flags @flags-sdk/openfeature cloudbees-openfeature-provider-node ``` -------------------------------- ### Run SvelteKit Application Locally Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Start your SvelteKit application locally using npm run dev. This command is used to test the integration and observe the toolbar's functionality. ```sh npm run dev ``` -------------------------------- ### Set up SvelteKit Server Hook Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/frameworks/sveltekit/index.mdx Configure the server hook using `createHandle` to make the toolbar aware of your application's feature flags. Ensure the `FLAGS_SECRET` environment variable is set. ```ts import { createHandle } from 'flags/sveltekit'; import { FLAGS_SECRET } from '$env/static/private'; import * as flags from '$lib/flags'; export const handle = createHandle({ secret: FLAGS_SECRET, flags }); ``` -------------------------------- ### Initialize GrowthBook SDK Client Source: https://github.com/vercel/flags/blob/main/apps/docs/content/docs/providers/growthbook.mdx Initializes the GrowthBook SDK client. This is typically done on-demand when a GrowthBook flag is evaluated and does not require manual invocation. ```typescript const growthbookClient = await growthbookAdapter.initialize(); ``` -------------------------------- ### Build Svelte project for production Source: https://github.com/vercel/flags/blob/main/tests/sveltekit-e2e/README.md Execute this command to create an optimized production build of your Svelte application. ```bash npm run build ``` -------------------------------- ### Dashboard Pages - Usage Source: https://github.com/vercel/flags/blob/main/skills/flags-sdk/references/nextjs.md Example of using the `dashboardFlag` in a Next.js page component. ```tsx export default async function DashboardPage() { const dashboard = await dashboardFlag(); return
{dashboard ? 'New Dashboard' : 'Old Dashboard'}
; } ```