Skip to content

Commit 7d6a928

Browse files
authored
chore: improve readme instructions (#93)
* chore: improve readme instructions * fix: shorten import LDOptions statement * fix: improve flag variable name
1 parent 4fc24ce commit 7d6a928

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

packages/sdk/cloudflare/README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,44 @@ This library supports using Cloudflare [Workers KV](https://developers.cloudflar
88

99
For more information, see the [SDK features guide](https://docs.launchdarkly.com/sdk/features/storing-data).
1010

11-
## Installation
11+
## Install
1212

1313
```shell
1414
npm i @launchdarkly/cloudflare-server-sdk
1515
```
1616

17-
or yarn:
18-
19-
```shell
20-
yarn add @launchdarkly/cloudflare-server-sdk
21-
```
22-
23-
In `wrangler.toml` in your worker project turn on the Node.js compatibility flag.
24-
This allows the SDK to use `node:events`:
17+
Then turn on the Node.js compatibility flag in your `wrangler.toml`. This allows the SDK to use `node:events`:
2518

2619
```toml
2720
compatibility_flags = [ "nodejs_compat" ]
2821
```
2922

3023
## Quickstart
3124

32-
Initialize the ldClient with the [Cloudflare KV namespace](https://developers.cloudflare.com/workers/runtime-apis/kv#kv-bindings) and your client side sdk key:
25+
Initialize the ldClient with your client side sdk key and the [Cloudflare KV namespace](https://developers.cloudflare.com/workers/runtime-apis/kv#kv-bindings):
3326

3427
```typescript
35-
import { init } from '@launchdarkly/cloudflare-server-sdk';
36-
37-
const ldClient = init(KV_NAMESPACE, 'YOUR CLIENT-SIDE SDK KEY');
28+
import { init as initLD } from '@launchdarkly/cloudflare-server-sdk';
29+
30+
export default {
31+
async fetch(request: Request, env: Bindings): Promise<Response> {
32+
const sdkKey = 'test-sdk-key';
33+
const flagKey = 'testFlag1';
34+
const context = { kind: 'user', key: 'test-user-key-1' };
35+
36+
// init the ldClient, wait and finally evaluate
37+
const client = initLD(sdkKey, env.LD_KV);
38+
await client.waitForInitialization();
39+
const flagValue = await client.variation(flagKey, context, false);
40+
41+
return new Response(`${flagKey}: ${flagValue}`);
42+
},
43+
};
3844
```
3945

40-
To learn more, head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/cloudflare).
46+
See the full [example app](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/cloudflare/example).
47+
48+
Read the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/cloudflare).
4149

4250
## Developing this SDK
4351

packages/sdk/cloudflare/example/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export default {
99
// start using ld
1010
const client = initLD(sdkKey, env.LD_KV);
1111
await client.waitForInitialization();
12-
const flag = await client.variation(flagKey, context, false);
12+
const flagValue = await client.variation(flagKey, context, false);
1313
const flagDetail = await client.variationDetail(flagKey, context, false);
1414
const allFlags = await client.allFlagsState(context);
1515

16-
const resp = `${flagKey}: ${flag}, detail: ${JSON.stringify(
16+
const resp = `${flagKey}: ${flagValue}, detail: ${JSON.stringify(
1717
flagDetail
1818
)}, allFlags: ${JSON.stringify(allFlags)}`;
1919

packages/shared/sdk-server-edge/src/utils/validateOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LDOptions as LDOptionsCommon } from '@launchdarkly/js-server-sdk-common/dist/api/options/LDOptions';
1+
import { LDOptions as LDOptionsCommon } from '@launchdarkly/js-server-sdk-common';
22

33
/**
44
* The Launchdarkly Edge SDKs configuration options. Only logger is officially

0 commit comments

Comments
 (0)