Skip to content

Commit 5f5eda3

Browse files
authored
feat: vercel edge sdk (#77)
* create new package * inspiration from cloudflare work * working version using local link in dev project * add missed file * add tests * use package.json * fix package.json reading * small stuff * update readme * some pr feedback * pull in main and build changes * move to using shared edge-common package * change featurestore to class implementation * rename file for clarity * add changelog * get tsc to build types * add types to export as well * update platforminfo * attempt switch to async * github actions changes * changes for typedoc * prettier * update readme * add required newlines * prettier again * remove todo from readme * pr feedback * add initial release config * add tests for createPlatformInfo * working tests for index.ts, need to fix types * type issues * type issues * prettier the comments * increase test coverage * linter * update release please bootstrap sha
1 parent a9f533a commit 5f5eda3

23 files changed

+622
-2
lines changed

.github/workflows/manual-publish-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- packages/shared/sdk-server-edge
1313
- packages/sdk/cloudflare
1414
- packages/sdk/server-node
15+
- packages/sdk/vercel
1516
name: Publish Documentation
1617
jobs:
1718
build-publish:

.github/workflows/manual-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
- packages/shared/sdk-server-edge
1414
- packages/sdk/cloudflare
1515
- packages/sdk/server-node
16+
- packages/sdk/vercel
1617
prerelease:
1718
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
1819
type: boolean

.github/workflows/release-please.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
package-sdk-server-edge-released: ${{ steps.release.outputs['packages/shared/sdk-server-edge--release_created'] }}
1414
package-cloudflare-released: ${{ steps.release.outputs['packages/sdk/cloudflare--release_created'] }}
1515
package-server-node-released: ${{ steps.release.outputs['packages/sdk/server-node--release_created'] }}
16+
package-vercel-released: ${{ steps.release.outputs['packages/sdk/vercel--release_created'] }}
1617
steps:
1718
- uses: google-github-actions/release-please-action@v3
1819
id: release
@@ -120,3 +121,23 @@ jobs:
120121
with:
121122
workspace_path: packages/sdk/server-node
122123
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
124+
125+
release-vercel:
126+
runs-on: ubuntu-latest
127+
needs: ['release-please']
128+
permissions:
129+
id-token: write
130+
contents: write
131+
if: ${{ needs.release-please.outputs.package-vercel-released }}
132+
steps:
133+
- uses: actions/checkout@v3
134+
- uses: actions/setup-node@v3
135+
with:
136+
node-version: 16.x
137+
registry-url: 'https://registry.npmjs.org'
138+
- id: release-common
139+
name: Full release of packages/sdk/vercel
140+
uses: ./actions/full-release
141+
with:
142+
workspace_path: packages/sdk/vercel
143+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}

.github/workflows/vercel.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: sdk/vercel
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main]
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-vercel:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-node@v3
19+
- id: shared
20+
name: Shared CI Steps
21+
uses: ./actions/ci
22+
with:
23+
workspace_name: '@launchdarkly/vercel-server-sdk'
24+
workspace_path: packages/sdk/vercel

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"packages/shared/sdk-server-edge",
77
"packages/sdk/server-node",
88
"packages/sdk/cloudflare",
9-
"packages/sdk/cloudflare/example"
9+
"packages/sdk/cloudflare/example",
10+
"packages/sdk/vercel"
1011
],
1112
"private": true,
1213
"scripts": {

packages/sdk/vercel/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to the LaunchDarkly SDK for Vercel Edge Config will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org).

packages/sdk/vercel/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# LaunchDarkly Vercel Edge SDK
2+
3+
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).
4+
5+
For more information, see the [SDK features guide](https://docs.launchdarkly.com/sdk/features/storing-data).
6+
7+
## Install
8+
9+
```shell
10+
npm i @launchdarkly/vercel-server-sdk
11+
```
12+
13+
or yarn:
14+
15+
```shell
16+
yarn add -D @launchdarkly/vercel-server-sdk
17+
```
18+
19+
## Quickstart
20+
21+
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:
22+
23+
```typescript
24+
import init from '@launchdarkly/vercel-server-sdk';
25+
import { createClient } from '@vercel/edge-config';
26+
27+
const edgeClient = createClient(process.env.EDGE_CONFIG);
28+
const ldClient = init('YOUR CLIENT-SIDE SDK KEY', edgeClient);
29+
30+
await ldClient.waitForInitialization();
31+
const ldContext = {
32+
kind: 'org',
33+
key: 'my-org-key',
34+
someAttribute: 'my-attribute-value',
35+
};
36+
const flagValue = await ldClient.variation('my-flag', ldContext, true);
37+
```
38+
39+
To learn more, head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/vercel).
40+
41+
## Developing this SDK
42+
43+
```shell
44+
# at js-core repo root
45+
yarn && yarn build && cd packages/sdk/vercel
46+
# run tests
47+
yarn test
48+
```
49+
50+
## About LaunchDarkly
51+
52+
- LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
53+
- Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
54+
- Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
55+
- Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
56+
- Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
57+
- LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
58+
- Explore LaunchDarkly
59+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
60+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
61+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
62+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"transform": { "^.+\\.ts?$": "ts-jest" },
3+
"testMatch": ["**/*.test.ts?(x)"],
4+
"testPathIgnorePatterns": ["node_modules", "example", "dist"],
5+
"modulePathIgnorePatterns": ["dist"],
6+
"testEnvironment": "node",
7+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
8+
"collectCoverageFrom": ["src/**/*.ts"]
9+
}

packages/sdk/vercel/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@launchdarkly/vercel-server-sdk",
3+
"version": "0.1.0",
4+
"description": "LaunchDarkly Server-Side SDK for Vercel Edge",
5+
"packageManager": "[email protected]",
6+
"keywords": [
7+
"launchdarkly",
8+
"vercel",
9+
"edge"
10+
],
11+
"type": "module",
12+
"exports": {
13+
"require": "./dist/cjs/src/index.js",
14+
"import": "./dist/esm/src/index.js"
15+
},
16+
"main": "./dist/cjs/src/index.js",
17+
"files": [
18+
"/dist"
19+
],
20+
"scripts": {
21+
"doc": "../../../scripts/build-doc.sh .",
22+
"build": "../../../scripts/build-package.sh",
23+
"tsw": "yarn tsc --watch",
24+
"start": "rimraf dist && yarn tsw",
25+
"lint": "eslint . --ext .ts",
26+
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)'",
27+
"test": "jest --ci --runInBand --coverage",
28+
"check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc"
29+
},
30+
"dependencies": {
31+
"@launchdarkly/js-server-sdk-common-edge": "0.0.2",
32+
"crypto-js": "^4.1.1"
33+
},
34+
"devDependencies": {
35+
"@types/crypto-js": "^4.1.1",
36+
"@types/jest": "^29.5.0",
37+
"@typescript-eslint/eslint-plugin": "^5.57.0",
38+
"@typescript-eslint/parser": "^5.57.0",
39+
"@vercel/edge-config": "^0.1.7",
40+
"eslint": "^8.37.0",
41+
"eslint-config-airbnb-base": "^15.0.0",
42+
"eslint-config-airbnb-typescript": "^17.0.0",
43+
"eslint-config-prettier": "^8.8.0",
44+
"eslint-plugin-import": "^2.27.5",
45+
"eslint-plugin-prettier": "^4.2.1",
46+
"jest": "^29.5.0",
47+
"launchdarkly-js-test-helpers": "^2.2.0",
48+
"prettier": "^2.8.7",
49+
"ts-jest": "^29.1.0",
50+
"typedoc": "0.23.26",
51+
"typescript": "^5.0.3"
52+
}
53+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { name, version } from '../package.json';
2+
3+
import createPlatformInfo from './createPlatformInfo';
4+
5+
describe('Vercel Platform Info', () => {
6+
it('platformData shows correct information', () => {
7+
const platformData = createPlatformInfo();
8+
9+
expect(platformData.platformData()).toEqual({
10+
name: 'Vercel Edge',
11+
});
12+
});
13+
14+
it('sdkData shows correct information', () => {
15+
const platformData = createPlatformInfo();
16+
17+
expect(platformData.sdkData()).toEqual({
18+
name,
19+
version,
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)