Skip to content

Commit fbc886a

Browse files
authored
launchDarkly » ldAdapter (#90)
* launchDarkly » ldAdapter * expose ldClient on adapter itself
1 parent ab4c41c commit fbc886a

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

.changeset/modern-boxes-fail.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@flags-sdk/launchdarkly': patch
3+
---
4+
5+
expose ldAdapter.ldClient

.changeset/twelve-shirts-pay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@flags-sdk/launchdarkly': patch
3+
---
4+
5+
expose as ldAdapter

packages/adapter-launchdarkly/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ npm i @flags-sdk/launchdarkly
1414

1515
**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.
1616

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

1919
```ts
20-
import { launchDarkly } from '@flags-sdk/launchdarkly';
20+
import { ldAdapter } from '@flags-sdk/launchdarkly';
2121
```
2222

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

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

3838
const identify = dedupe(async (): Promise<LDContext> => {
3939
return {
@@ -44,7 +44,7 @@ const identify = dedupe(async (): Promise<LDContext> => {
4444
export const showBanner = flag<boolean, LDContext>({
4545
key: 'show-banner',
4646
identify,
47-
adapter: launchDarkly(),
47+
adapter: ldAdapter(),
4848
});
4949
```
5050

packages/adapter-launchdarkly/src/index.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ export function createLaunchDarklyAdapter({
3535
projectSlug: string;
3636
clientSideId: string;
3737
edgeConfigConnectionString: string;
38-
}) {
38+
}): {
39+
<ValueType>(
40+
options?: AdapterOptions<ValueType>,
41+
): Adapter<ValueType, LDContext>;
42+
/** The LaunchDarkly client instance used by the adapter. */
43+
ldClient: LDClient;
44+
} {
3945
const edgeConfigClient = createClient(edgeConfigConnectionString);
4046
const ldClient = init(clientSideId, edgeConfigClient);
4147

42-
return function launchDarklyAdapter<ValueType>(
48+
const launchDarklyAdapter = function launchDarklyAdapter<ValueType>(
4349
options: AdapterOptions<ValueType> = {},
44-
): Adapter<ValueType, LDContext> & { ldClient: LDClient } {
50+
): Adapter<ValueType, LDContext> {
4551
return {
46-
/** The LaunchDarkly client instance used by the adapter. */
47-
ldClient,
4852
origin(key) {
4953
return `https://app.launchdarkly.com/projects/${projectSlug}/flags/${key}/`;
5054
},
@@ -58,9 +62,13 @@ export function createLaunchDarklyAdapter({
5862
},
5963
};
6064
};
65+
66+
launchDarklyAdapter.ldClient = ldClient;
67+
68+
return launchDarklyAdapter;
6169
}
6270

63-
export function launchDarkly<ValueType>(
71+
export function ldAdapter<ValueType>(
6472
options?: AdapterOptions<ValueType>,
6573
): Adapter<ValueType, LDContext> {
6674
if (!defaultLaunchDarklyAdapter) {
@@ -77,3 +85,10 @@ export function launchDarkly<ValueType>(
7785

7886
return defaultLaunchDarklyAdapter(options);
7987
}
88+
89+
/**
90+
* This is the previous name for the LaunchDarkly adapter.
91+
*
92+
* @deprecated Use `ldAdapter` instead.
93+
*/
94+
export const launchDarkly = ldAdapter;

0 commit comments

Comments
 (0)