API ReferenceAdapters

@flags-sdk/edge-config

The @flags-sdk/edge-config package provides a basic adapter for defining feature flags powered by Vercel Edge Config

Learn more about Adapters

Installation

Follow the Quickstart, then add the Edge Config adapter.

Install desired dependencies

pnpm i @flags-sdk/edge-config

Set relevant variables

.env.local
EDGE_CONFIG="edge-config-connection-string"

Usage

flags.ts
import { flag } from 'flags/next';
import { edgeConfigAdapter } from '@flags-sdk/edge-config';
 
export const exampleFlag = flag({
  // Will load the `flags` key from Edge Config
  adapter: edgeConfigAdapter(),
  // Will get the `example-flag` key from the `flags` object
  key: 'example-flag',
});

Your Edge Config should be managed on the dashboard as follows:

{
  // `flags` is the default used by the Edge Config adapter
  "flags": {
    // Flags using the adapter should have their `key` defined here
    "example-flag": true,
    "another-example-flag": false,
  }
}

API Reference

edgeConfigAdapter

The adapter assumes that there is an EDGE_CONFIG environment variable set with a connection string, and that it contains a flags object with each key corresponding to a flag you define in code.

flags.ts
import { edgeConfigAdapter } from '@flags-sdk/edge-config';
 
export const exampleFlag = flag({
  adapter: edgeConfigAdapter(),
  key: 'example-flag',
});

createEdgeConfigAdapter

To customize these options you can import and call createEdgeConfigAdapter manually.

Option keyTypeDescription
connectionString`stringEdgeConfigClient`
options.edgeConfigItemKeystringDefaults to flags
options.teamSlugstringThe team slug used for your team in the Vercel dashboard, used to create links to your Edge Config
flags.ts
import { createEdgeConfigAdapter } from '@flags-sdk/edge-config';
 
const myEdgeConfigAdapter = createEdgeConfigAdapter({
  connectionString: process.env.OTHER_EDGE_CONFIG_CONNECTION_STRING,
  options: {
    edgeConfigItemKey: 'other-flags-key',
    teamSlug: 'my-vercel-team-slug',
  },
});
 
export const exampleFlag = flag({
  adapter: myEdgeConfigAdapter(),
  key: 'example-flag',
});

Read More

Read more about Edge Config, Flags SDK, and the Edge Config adapter.