diff --git a/.changeset/launchdarkly-experimentation-config.md b/.changeset/launchdarkly-experimentation-config.md new file mode 100644 index 00000000..b48f994b --- /dev/null +++ b/.changeset/launchdarkly-experimentation-config.md @@ -0,0 +1,21 @@ +--- +'@flags-sdk/launchdarkly': major +--- + +Support the native LaunchDarkly Marketplace integration. + +**Breaking changes:** + +- The default adapter (`ldAdapter`) now reads the Edge Config connection string from the `EXPERIMENTATION_CONFIG` environment variable instead of `EDGE_CONFIG`. This aligns with the native LaunchDarkly Marketplace integration and matches the behavior of other adapters (e.g. Statsig). `EDGE_CONFIG` is no longer read by the default adapter. The error thrown when `EXPERIMENTATION_CONFIG` is not set changed to `LaunchDarkly Adapter: Missing EXPERIMENTATION_CONFIG environment variable`. + + **If you use the legacy LaunchDarkly Vercel integration** (which provides the connection string as `EDGE_CONFIG`), pass the connection string explicitly with `createLaunchDarklyAdapter`: + + ```ts + import { createLaunchDarklyAdapter } from '@flags-sdk/launchdarkly'; + + const ldAdapter = createLaunchDarklyAdapter({ + projectSlug: process.env.LAUNCHDARKLY_PROJECT_SLUG, + clientSideId: process.env.LAUNCHDARKLY_CLIENT_SIDE_ID, + edgeConfigConnectionString: process.env.EDGE_CONFIG, + }); + ``` diff --git a/apps/docs/content/docs/providers/launchdarkly.mdx b/apps/docs/content/docs/providers/launchdarkly.mdx index 0f846946..b367d232 100644 --- a/apps/docs/content/docs/providers/launchdarkly.mdx +++ b/apps/docs/content/docs/providers/launchdarkly.mdx @@ -49,21 +49,28 @@ 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, + // Legacy integrations that provide the connection string as `EDGE_CONFIG` + // can pass it explicitly here. + edgeConfigConnectionString: + process.env.EXPERIMENTATION_CONFIG ?? process.env.EDGE_CONFIG, }); ``` -| Option key | Type | Description | -| ---------------------------- | ---------| ----------------------------- | -| `projectSlug` | `string` | LaunchDarkly project slug | -| `clientSideId` | `string` | LaunchDarkly client-side ID | -| `edgeConfigConnectionString` | `string` | Edge Config connection string | +| Option key | Type | Description | +| ---------------------------- | ---------| ------------------------------------------------------------------ | +| `projectSlug` | `string` | LaunchDarkly project slug | +| `clientSideId` | `string` | LaunchDarkly client-side ID | +| `edgeConfigConnectionString` | `string` | Edge Config connection string | The default LaunchDarkly adapter configures itself based on the following environment variables: - `LAUNCHDARKLY_CLIENT_SIDE_ID` _(required)_ → `clientSideId` - `LAUNCHDARKLY_PROJECT_SLUG` _(required)_ → `projectSlug` -- `EDGE_CONFIG` _(required)_ → `edgeConfigConnectionString` +- `EXPERIMENTATION_CONFIG` _(required)_ → `edgeConfigConnectionString` + +The native LaunchDarkly [Marketplace integration](https://vercel.com/marketplace/launchdarkly) exposes the Edge Config connection string as `EXPERIMENTATION_CONFIG` when Edge Config is enabled for the collection. + +If you use the legacy LaunchDarkly Vercel integration, which provides the connection string as `EDGE_CONFIG`, set `EXPERIMENTATION_CONFIG` to the same value, or use `createLaunchDarklyAdapter` to pass `edgeConfigConnectionString` explicitly. --- @@ -143,7 +150,7 @@ The LaunchDarkly adapter loads the configuration from [Edge Config](https://verc Edge Config is a global, ultra-low latency store which uses active replication and is specifically designed for serving feature flag configuration. -The default LaunchDarkly adapter, exported as `ldAdapter`, will automatically connect to Edge Config when the required environment variables are set. +The default LaunchDarkly adapter, exported as `ldAdapter`, will automatically connect to Edge Config when the required environment variables are set. It reads the connection string from `EXPERIMENTATION_CONFIG` (provided by the native Marketplace integration). --- diff --git a/packages/adapter-launchdarkly/README.md b/packages/adapter-launchdarkly/README.md index 6b6ae73a..9cae5cd3 100644 --- a/packages/adapter-launchdarkly/README.md +++ b/packages/adapter-launchdarkly/README.md @@ -25,10 +25,17 @@ The default adapter uses the following environment variables to configure itself ```sh 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" +# Provided by the LaunchDarkly Marketplace integration when Edge Config is +# enabled for the collection. +export EXPERIMENTATION_CONFIG="https://edge-config.vercel.com/ecfg_abdc1234?token=xxx-xxx-xxx" ``` +> **Using the legacy LaunchDarkly Vercel integration?** The default adapter reads +> the Edge Config connection string from `EXPERIMENTATION_CONFIG` only. If your +> project provides the connection string as `EDGE_CONFIG`, set +> `EXPERIMENTATION_CONFIG` to the same value, or pass it explicitly with +> [`createLaunchDarklyAdapter`](#custom-adapter). + ## Example ```ts @@ -57,8 +64,11 @@ import { createLaunchDarklyAdapter } from "@flags-sdk/launchdarkly"; const adapter = createLaunchDarklyAdapter({ projectSlug: "my-project", - ldClientSideKey: "612376f91b8f5713a58777a1", - edgeConfigConnectionString: process.env.EDGE_CONFIG, + clientSideId: "612376f91b8f5713a58777a1", + // Legacy integrations that provide the connection string as `EDGE_CONFIG` + // can pass it explicitly here. + edgeConfigConnectionString: + process.env.EXPERIMENTATION_CONFIG ?? process.env.EDGE_CONFIG, }); ``` diff --git a/packages/adapter-launchdarkly/src/index.test.ts b/packages/adapter-launchdarkly/src/index.test.ts index 6e6feb83..2bcb255b 100644 --- a/packages/adapter-launchdarkly/src/index.test.ts +++ b/packages/adapter-launchdarkly/src/index.test.ts @@ -24,7 +24,7 @@ describe('ldAdapter', () => { describe('with a missing environment', () => { it('should throw an error', () => { expect(() => ldAdapter.variation()).toThrowError( - 'LaunchDarkly Adapter: Missing EDGE_CONFIG environment variable', + 'LaunchDarkly Adapter: Missing EXPERIMENTATION_CONFIG environment variable', ); }); }); @@ -33,7 +33,8 @@ describe('ldAdapter', () => { beforeAll(() => { process.env.LAUNCHDARKLY_PROJECT_SLUG = 'test-project'; process.env.LAUNCHDARKLY_CLIENT_SIDE_ID = 'test-client-side-id'; - process.env.EDGE_CONFIG = 'https://edge-config.com/test-edge-config'; + process.env.EXPERIMENTATION_CONFIG = + 'https://edge-config.com/test-experimentation-config'; }); it('should expose the ldClient', () => { diff --git a/packages/adapter-launchdarkly/src/index.ts b/packages/adapter-launchdarkly/src/index.ts index d3f0972c..54779a7e 100644 --- a/packages/adapter-launchdarkly/src/index.ts +++ b/packages/adapter-launchdarkly/src/index.ts @@ -108,7 +108,7 @@ export function createLaunchDarklyAdapter({ function getOrCreateDeaultAdapter() { if (!defaultLaunchDarklyAdapter) { - const edgeConfigConnectionString = assertEnv('EDGE_CONFIG'); + const edgeConfigConnectionString = assertEnv('EXPERIMENTATION_CONFIG'); const clientSideId = assertEnv('LAUNCHDARKLY_CLIENT_SIDE_ID'); const projectSlug = assertEnv('LAUNCHDARKLY_PROJECT_SLUG');