Skip to content

Commit

Permalink
launchDarkly » ldAdapter (#90)
Browse files Browse the repository at this point in the history
* launchDarkly » ldAdapter

* expose ldClient on adapter itself
  • Loading branch information
dferber90 authored Mar 8, 2025
1 parent ab4c41c commit fbc886a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-boxes-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flags-sdk/launchdarkly': patch
---

expose ldAdapter.ldClient
5 changes: 5 additions & 0 deletions .changeset/twelve-shirts-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flags-sdk/launchdarkly': patch
---

expose as ldAdapter
8 changes: 4 additions & 4 deletions packages/adapter-launchdarkly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ npm i @flags-sdk/launchdarkly

**NOTE:** The [LaunchDarkly Vercel integration](https://vercel.com/integrations/launchdarkly) must be installed on your account, as this adapter loads LaunchDarkly from Edge Config. The adapter can not be used without Edge Config.

Import the default adapter instance `launchDarkly` from `@flags-sdk/launchdarkly`:
Import the default adapter instance `ldAdapter` from `@flags-sdk/launchdarkly`:

```ts
import { launchDarkly } from '@flags-sdk/launchdarkly';
import { ldAdapter } from '@flags-sdk/launchdarkly';
```

The default adapter uses the following environment variables to configure itself:
Expand All @@ -33,7 +33,7 @@ export EDGE_CONFIG="https://edge-config.vercel.com/ecfg_abdc1234?token=xxx-xxx-x

```ts
import { flag, dedupe } from 'flags/next';
import { launchDarkly, type LDContext } from '@flags-sdk/launchdarkly';
import { ldAdapter, type LDContext } from '@flags-sdk/launchdarkly';

const identify = dedupe(async (): Promise<LDContext> => {
return {
Expand All @@ -44,7 +44,7 @@ const identify = dedupe(async (): Promise<LDContext> => {
export const showBanner = flag<boolean, LDContext>({
key: 'show-banner',
identify,
adapter: launchDarkly(),
adapter: ldAdapter(),
});
```

Expand Down
27 changes: 21 additions & 6 deletions packages/adapter-launchdarkly/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ export function createLaunchDarklyAdapter({
projectSlug: string;
clientSideId: string;
edgeConfigConnectionString: string;
}) {
}): {
<ValueType>(
options?: AdapterOptions<ValueType>,
): Adapter<ValueType, LDContext>;
/** The LaunchDarkly client instance used by the adapter. */
ldClient: LDClient;
} {
const edgeConfigClient = createClient(edgeConfigConnectionString);
const ldClient = init(clientSideId, edgeConfigClient);

return function launchDarklyAdapter<ValueType>(
const launchDarklyAdapter = function launchDarklyAdapter<ValueType>(
options: AdapterOptions<ValueType> = {},
): Adapter<ValueType, LDContext> & { ldClient: LDClient } {
): Adapter<ValueType, LDContext> {
return {
/** The LaunchDarkly client instance used by the adapter. */
ldClient,
origin(key) {
return `https://app.launchdarkly.com/projects/${projectSlug}/flags/${key}/`;
},
Expand All @@ -58,9 +62,13 @@ export function createLaunchDarklyAdapter({
},
};
};

launchDarklyAdapter.ldClient = ldClient;

return launchDarklyAdapter;
}

export function launchDarkly<ValueType>(
export function ldAdapter<ValueType>(
options?: AdapterOptions<ValueType>,
): Adapter<ValueType, LDContext> {
if (!defaultLaunchDarklyAdapter) {
Expand All @@ -77,3 +85,10 @@ export function launchDarkly<ValueType>(

return defaultLaunchDarklyAdapter(options);
}

/**
* This is the previous name for the LaunchDarkly adapter.
*
* @deprecated Use `ldAdapter` instead.
*/
export const launchDarkly = ldAdapter;

0 comments on commit fbc886a

Please sign in to comment.