Skip to Content
Octopus Energy Packages

Global Config

Adapter for reading flags from Vercel Global Config

@octopus-energy/flags/global-config provides an adapter that reads flag definitions from a Vercel Global Config item and utilities for surfacing flag metadata to the Flags Explorer.

Identity is not supported

Global Config decisions use only the stored default and activation periods. Do not use this adapter for visitor targeting or identity-based A/B tests because it does not implement the identify function.

import {
  createGlobalConfigAdapter,
  globalConfigAdapter,
  getGlobalConfigProviderData,
} from "@octopus-energy/flags/global-config";

createGlobalConfigAdapter

Creates an adapter that reads flag values from a Global Config item. Use it with the Flags SDK adapter option:

import { createGlobalConfigAdapter } from "@octopus-energy/flags/global-config";
import { flag } from "flags/next";

const adapter = createGlobalConfigAdapter({ key: "flags" });

export const checkoutRedesign = flag({
  key: "checkout-redesign",
  adapter,
  defaultValue: false,
});

Omit key to read the item named by OE_FLAGS_GLOBAL_CONFIG_KEY, falling back to flags when the environment variable is unset. An explicit key takes precedence.

createGlobalConfigAdapter

Prop

Type

CreateGlobalConfigAdapterOptions

Prop

Type

globalConfigAdapter

A default adapter that initializes lazily from process.env.GLOBAL_CONFIG, falling back to process.env.EDGE_CONFIG. Uses process.env.VERCEL_TEAM_SLUG for the dashboard origin link when available.

import { globalConfigAdapter } from "@octopus-energy/flags/global-config";
import { flag } from "flags/next";

export const checkoutRedesign = flag({
  key: "checkout-redesign",
  adapter: globalConfigAdapter,
  defaultValue: false,
});

Required environment variable

globalConfigAdapter throws if neither GLOBAL_CONFIG nor EDGE_CONFIG is set.

getGlobalConfigProviderData

Returns ProviderData for global-config-backed flags, with options, description, and origin populated from the store. Use it in the Flags Toolbar discovery endpoint to surface richer metadata than the generic getProviderData from flags/next.

getGlobalConfigProviderData

Prop

Type

import { getGlobalConfigProviderData } from "@octopus-energy/flags/global-config";
import * as flags from "../../flags";

const providerData = await getGlobalConfigProviderData(flags);

Only flags that use the global config adapter are included (identified by their adapter's adapterId). Non-global-config flags in the record are skipped.

Global Config item format

The Global Config item is a record of flag definitions keyed by flag name:

{
  "checkout-redesign": {
    "kind": "boolean",
    "defaultVariant": "off",
    "variants": {
      "on": { "value": true, "label": "Enabled" },
      "off": { "value": false, "label": "Disabled" }
    }
  },
  "headline-variant": {
    "kind": "string",
    "defaultVariant": "control",
    "variants": {
      "control": { "value": "control", "label": "Control" },
      "short": { "value": "short", "label": "Short headline" },
      "long": { "value": "long", "label": "Long headline" }
    }
  }
}

Each flag entry has the following shape:

FieldTypeDescription
kind"boolean" | "string" | "number" | "json"Value type
defaultVariantstringKey into variants used when no activation is active
variantsRecord<string, { label?: string; value: JsonValue }>Keyed variant definitions
descriptionstring (optional)Human-readable description
activationsArray<Activation> (optional)Time-based variant overrides

Activation periods

The optional activations array schedules a variant to be served between two dates:

{
  "banner": {
    "kind": "string",
    "defaultVariant": "none",
    "variants": {
      "none": { "value": "none" },
      "promo": { "value": "summer-sale", "label": "Summer Sale" }
    },
    "activations": [
      {
        "variant": "promo",
        "startDate": "2026-07-01T00:00:00Z",
        "endDate": "2026-07-31T23:59:59Z"
      }
    ]
  }
}
FieldTypeDescription
variantstringKey in variants to activate
startDatestring (ISO 8601)When the activation begins (UTC)
endDatestring (optional)Exclusive end time (omit for open-ended)

When provided, endDate must be strictly later than startDate and is exclusive. Activation periods must not overlap, but adjacent periods can share a boundary. At runtime, the adapter evaluates activations against the current time and falls back to defaultVariant when none match.

Types

The entry point also exports Zod schemas and inferred types for the Global Config flag format:

ExportDescription
GlobalConfigFlagValidated flag schema (variants required)
GlobalConfigFlagInputLoose input schema (variants optional)
GlobalConfigFlagKindZod enum: boolean, string, number, json
GlobalConfigFlagOptionSingle variant entry: { label?: string; value: JsonValue }
GlobalConfigFlagVariantsRecord<string, GlobalConfigFlagOption>
GlobalConfigFlagActivationActivation period: { variant, startDate, endDate? }
GlobalConfigFlagStoreRecord<string, GlobalConfigFlag>

On this page