Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/launchdarkly-experimentation-config.md
Original file line number Diff line number Diff line change
@@ -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,
});
```
23 changes: 15 additions & 8 deletions apps/docs/content/docs/providers/launchdarkly.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.


---
Expand Down Expand Up @@ -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).

---

Expand Down
18 changes: 14 additions & 4 deletions packages/adapter-launchdarkly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
```

Expand Down
5 changes: 3 additions & 2 deletions packages/adapter-launchdarkly/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
});
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-launchdarkly/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Loading