Skip to content

Commit 93d8b94

Browse files
committed
Merge remote-tracking branch 'origin/main' into ctawiah/sc-203998/initial-rollup-setup
2 parents c380d8c + d25f327 commit 93d8b94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+875
-100
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
project: './tsconfig.eslint.json',
99
},
1010
plugins: ['@typescript-eslint', 'prettier'],
11-
ignorePatterns: ['**/dist/**'],
11+
ignorePatterns: ['**/dist/**', '**/vercel/examples/**'],
1212
rules: {
1313
'prettier/prettier': ['error'],
1414
'class-methods-use-this': 'off',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"packages/sdk/cloudflare",
1010
"packages/sdk/cloudflare/example",
1111
"packages/sdk/vercel",
12-
"packages/sdk/vercel/example-vercel",
12+
"packages/sdk/vercel/examples/complete",
13+
"packages/sdk/vercel/examples/route-handler",
1314
"packages/sdk/akamai",
1415
"packages/sdk/akamai/example",
1516
"packages/sdk/akamai-edgekv",

packages/sdk/vercel/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
[![NPM][sdk-vercel-dm-badge]][sdk-vercel-npm-link]
77
[![NPM][sdk-vercel-dt-badge]][sdk-vercel-npm-link]
88

9-
This library supports using Vercel [Edge Config](https://vercel.com/docs/concepts/edge-network/edge-config) to replace the default in-memory feature store of the [LaunchDarkly Node.js SDK](https://github.com/launchdarkly/vercel-server-sdk).
9+
This library supports using Vercel [Edge Config](https://vercel.com/docs/concepts/edge-network/edge-config) to replace the default in-memory feature store of the [LaunchDarkly Node.js SDK](https://github.com/launchdarkly/node-server-sdk).
1010

11-
For more information, see the [SDK features guide](https://docs.launchdarkly.com/sdk/features/storing-data).
11+
## The LaunchDarkly Vercel integration is required
12+
13+
This SDK requires [LaunchDarkly's Vercel integration](https://docs.launchdarkly.com/integrations/vercel?q=verc) to push feature flag data into a Vercel Edge Config. The Vercel integration is available to customers on an Enterprise plan. To learn more, [read about our pricing](https://launchdarkly.com/pricing/). To upgrade your plan, [contact Sales](https://launchdarkly.com/contact-sales/).
14+
15+
For more information, see the [Vercel SDK reference](https://docs.launchdarkly.com/sdk/edge/vercel).
1216

1317
## Install
1418

@@ -22,16 +26,16 @@ or yarn:
2226
yarn add -D @launchdarkly/vercel-server-sdk
2327
```
2428

25-
## Quickstart
29+
## Quick start
2630

27-
Initialize the ldClient with the [Vercel Edge SDK](https://vercel.com/docs/concepts/edge-network/edge-config/edge-config-sdk) and your LaunchDarkly client side sdk key:
31+
Initialize the ldClient with the [Vercel Edge SDK](https://vercel.com/docs/concepts/edge-network/edge-config/edge-config-sdk) and your LaunchDarkly [client-side ID](https://docs.launchdarkly.com/sdk/concepts/client-side-server-side#client-side-id):
2832

2933
```typescript
30-
import init from '@launchdarkly/vercel-server-sdk';
34+
import { init } from '@launchdarkly/vercel-server-sdk';
3135
import { createClient } from '@vercel/edge-config';
3236

3337
const edgeClient = createClient(process.env.EDGE_CONFIG);
34-
const ldClient = init('YOUR CLIENT-SIDE SDK KEY', edgeClient);
38+
const ldClient = init('YOUR CLIENT-SIDE ID', edgeClient);
3539

3640
await ldClient.waitForInitialization();
3741
const ldContext = {
@@ -42,7 +46,7 @@ const ldContext = {
4246
const flagValue = await ldClient.variation('my-flag', ldContext, true);
4347
```
4448

45-
To learn more, head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/vercel).
49+
To learn more, see the [examples](examples/README.md) in this repository or head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/vercel).
4650

4751
## Developing this SDK
4852

packages/sdk/vercel/example-vercel/README.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/sdk/vercel/example-vercel/src/app/api/hello/route.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# LaunchDarkly Vercel Edge SDK examples
2+
3+
The following examples showcase using the LaunchDarkly Vercel Edge SDK to evaluate feature flags in Vercel's [Edge Runtime](https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime). Both examples require the use of the [LaunchDarkly Vercel integration](https://docs.launchdarkly.com/integrations/vercel) to push feature flag data into Vercel's Edge Config.
4+
5+
## [Complete example](complete/README.md)
6+
7+
This example shows how to evaluate feature flags in Vercel's edge runtime using the [LaunchDarkly Vercel SDK](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/vercel). Two primary use cases are highlighted:
8+
9+
1. Bootstrapping feature flags from the edge runtime and consuming them in the [LaunchDarkly Client-side SDK for React](https://github.com/launchdarkly/react-client-sdk). This is leveraging feature flags in edge-rendered pages while still maintaining the events and ergonomics provided by the React SDK. You can see details in [`app/layout.tsx`](./app/layout.tsx) and [`components/launchdarklyProvider.tsx`](./components/launchdarklyProvider.tsx).
10+
2. Evaluating feature flags in the [Edge Middleware](https://vercel.com/docs/concepts/functions/edge-middleware). This can be seen in [`middleware.ts`](./middleware.ts).
11+
12+
### Demo
13+
14+
https://hello-vercel-edge.vercel.app/
15+
16+
## [Route Handler example](route-handler/README.md)
17+
18+
This is an example test app to showcase the usage of the Vercel LaunchDarkly
19+
SDK to evaluate a feature flag in a [Route Handler](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) using [Vercel's edge runtime](https://nextjs.org/docs/app/building-your-application/routing/router-handlers#edge-and-nodejs-runtimes).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "next/core-web-vitals"
4+
}
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

3-
# dependencies
3+
# Dependencies
44
/node_modules
55
/.pnp
66
.pnp.js
77

8-
# testing
8+
# Testing
99
/coverage
1010

11-
# next.js
11+
# Next.js
1212
/.next/
1313
/out/
1414

15-
# production
15+
# VS code
16+
/.vscode
17+
18+
# Production
1619
/build
1720

18-
# misc
21+
# Misc
1922
.DS_Store
2023
*.pem
2124

22-
# debug
25+
# Debug
2326
npm-debug.log*
2427
yarn-debug.log*
2528
yarn-error.log*
2629

27-
# local env files
28-
.env*.local
30+
# Local ENV files
31+
.env.local
32+
.env.development.local
33+
.env.test.local
34+
.env.production.local
2935

30-
# vercel
36+
# Vercel
3137
.vercel
3238

39+
# Turborepo
40+
.turbo
41+
3342
# typescript
34-
*.tsbuildinfo
35-
next-env.d.ts
36-
.vscode
43+
*.tsbuildinfo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Complete example app for Vercel LaunchDarkly SDK
2+
3+
This example shows how to evaluate feature flags in Vercel's edge runtime using the [LaunchDarkly Vercel SDK](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/vercel). Two primary use cases are highlighted:
4+
5+
1. Bootstrapping feature flags from the edge runtime and consuming them in the [LaunchDarkly Client-side SDK for React](https://github.com/launchdarkly/react-client-sdk). This is leveraging feature flags in edge-rendered pages while still maintaining the events and ergonomics provided by the React SDK. You can see details in [`app/layout.tsx`](./app/layout.tsx) and [`components/launchdarklyProvider.tsx`](./components/launchdarklyProvider.tsx).
6+
2. Evaluating feature flags in the [Edge Middleware](https://vercel.com/docs/concepts/functions/edge-middleware). This can be seen in [`middleware.ts`](./middleware.ts).
7+
8+
## Demo
9+
10+
https://hello-vercel-edge.vercel.app/
11+
12+
## Local development
13+
14+
#### Create a new LaunchDarkly project and flags
15+
16+
For simplicity, we recommend [creating a new LaunchDarkly project](https://docs.launchdarkly.com/home/organize/projects/?q=create+proj) for this example app. After creating a new project, create the following feature flags with Client-side SDK availability:
17+
18+
- `bootstrap-flags` - (Boolean) - This flag will determine whether or not the LaunchDarkly React SDK will bootstrap feature flags from the edge.
19+
- `show-debugging-info` - (Boolean) - This flag is used to expose the current flag values.
20+
- `hero-text` - (String) - This flag is used to dynamically change the hero text. You can make the variations anything you want, e.g. "The best way to buy the products you love."
21+
- `enable-hot-dog-favicon` - (Boolean) - This flag is used in middleware.ts to dynamically load a different favicon.
22+
- `store-closed` - (Boolean) - This flag is evaluated in `middleware.ts` and can be used to load a different home page when the store is closed.
23+
24+
#### Set up the LaunchDarkly Vercel integration
25+
26+
You will need to have the LaunchDarkly Vercel integration configured to push feature flag data to your Vercel Edge Config. Read the [Vercel documentation](https://docs.launchdarkly.com/integrations/vercel/) to set up the integration. Be sure to connect the project you created above.
27+
28+
#### Set up environment variables
29+
30+
1. Copy this directory in a new repository.
31+
2. Create a new Vercel project based on the new repository.
32+
3. [Add a new environment variable to your project](https://vercel.com/docs/concepts/projects/environment-variables) named `LD_CLIENT_SIDE_ID` and set it to the LaunchDarkly client-side ID for the **Test** environment in the project you created above.
33+
4. Follow [Vercel's documentation](https://vercel.com/docs/storage/edge-config/get-started) to connect an Edge Config to your new project.
34+
5. Run the following command to link your local codebase to your Vercel project:
35+
36+
```shell
37+
vercel link
38+
```
39+
40+
6. Run the following command to sync your projects environment variables in your development environment:
41+
42+
```shell
43+
vercel env pull .env.development.local
44+
```
45+
46+
7. After completing the guide above, you should have linked this example app to your Vercel project and created an `.env.development.local`.
47+
8. Verify the contents of `.env.development.local` have values for the `LD_CLIENT_SIDE_ID` and `EDGE_CONFIG`.
48+
9. Run the following command to install all dependencies:
49+
50+
```shell
51+
yarn
52+
```
53+
54+
10. Run the following command to start your development environment:
55+
56+
```shell
57+
yarn dev
58+
```

0 commit comments

Comments
 (0)