Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
66c5bb4
create new package
monsagri Apr 11, 2023
120a6c6
inspiration from cloudflare work
monsagri Apr 12, 2023
914fbc8
working version using local link in dev project
monsagri Apr 12, 2023
ebc6d26
add missed file
monsagri Apr 12, 2023
1b176c0
add tests
monsagri Apr 13, 2023
6f0d25e
use package.json
monsagri Apr 13, 2023
30e3f1b
fix package.json reading
monsagri Apr 13, 2023
e6cda5b
small stuff
monsagri Apr 13, 2023
7ff9fc6
update readme
monsagri Apr 13, 2023
f4b8052
some pr feedback
monsagri Apr 13, 2023
a15947a
Merge branch 'main' into ffeldberg/sc-194414/update-the-sdk-to-pull-i…
monsagri Apr 20, 2023
d4e8b0a
Merge branch 'main' into ffeldberg/sc-194414/update-the-sdk-to-pull-i…
monsagri Apr 21, 2023
4153c36
pull in main and build changes
monsagri Apr 21, 2023
7ee3009
move to using shared edge-common package
monsagri Apr 21, 2023
6f65333
change featurestore to class implementation
monsagri Apr 21, 2023
9a80e54
rename file for clarity
monsagri Apr 21, 2023
91e3ebd
add changelog
monsagri Apr 21, 2023
9503f1c
get tsc to build types
monsagri Apr 21, 2023
42338bb
add types to export as well
monsagri Apr 21, 2023
0dbaa18
update platforminfo
monsagri Apr 21, 2023
4d85d4a
attempt switch to async
monsagri Apr 21, 2023
8767f7c
github actions changes
monsagri Apr 21, 2023
458a2d9
changes for typedoc
monsagri Apr 21, 2023
54998a1
prettier
monsagri Apr 21, 2023
4b7759e
update readme
monsagri Apr 21, 2023
6f346c7
add required newlines
monsagri Apr 21, 2023
f83e2d6
prettier again
monsagri Apr 21, 2023
24893ed
remove todo from readme
monsagri Apr 21, 2023
4a8d795
pr feedback
monsagri Apr 24, 2023
9f414db
add initial release config
monsagri Apr 24, 2023
bfd66c4
add tests for createPlatformInfo
monsagri Apr 24, 2023
8bfd57c
working tests for index.ts, need to fix types
monsagri Apr 24, 2023
d32cb69
type issues
monsagri Apr 24, 2023
b475f37
type issues
monsagri Apr 24, 2023
f4e3e97
prettier the comments
monsagri Apr 24, 2023
d34fbc5
increase test coverage
monsagri Apr 24, 2023
71e0b32
Merge branch 'main' into ffeldberg/sc-194414/update-the-sdk-to-pull-i…
monsagri Apr 24, 2023
bc70619
linter
monsagri Apr 24, 2023
41f5d0c
update release please bootstrap sha
monsagri Apr 25, 2023
7b0d851
Merge branch 'main' into ffeldberg/sc-194414/update-the-sdk-to-pull-i…
monsagri Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/manual-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- packages/shared/sdk-server-edge
- packages/sdk/cloudflare
- packages/sdk/server-node
- packages/sdk/vercel
name: Publish Documentation
jobs:
build-publish:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- packages/shared/sdk-server-edge
- packages/sdk/cloudflare
- packages/sdk/server-node
- packages/sdk/vercel
prerelease:
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
type: boolean
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
package-sdk-server-edge-released: ${{ steps.release.outputs['packages/shared/sdk-server-edge--release_created'] }}
package-cloudflare-released: ${{ steps.release.outputs['packages/sdk/cloudflare--release_created'] }}
package-server-node-released: ${{ steps.release.outputs['packages/sdk/server-node--release_created'] }}
package-vercel-released: ${{ steps.release.outputs['packages/sdk/vercel--release_created'] }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
Expand Down Expand Up @@ -120,3 +121,23 @@ jobs:
with:
workspace_path: packages/sdk/server-node
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}

release-vercel:
runs-on: ubuntu-latest
needs: ['release-please']
permissions:
id-token: write
contents: write
if: ${{ needs.release-please.outputs.package-vercel-released }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- id: release-common
name: Full release of packages/sdk/vercel
uses: ./actions/full-release
with:
workspace_path: packages/sdk/vercel
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
24 changes: 24 additions & 0 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: sdk/vercel

on:
push:
branches: [main]
paths-ignore:
- '**.md' #Do not need to run CI for markdown changes.
pull_request:
branches: [main]
paths-ignore:
- '**.md'

jobs:
build-test-vercel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- id: shared
name: Shared CI Steps
uses: ./actions/ci
with:
workspace_name: '@launchdarkly/vercel-server-sdk'
workspace_path: packages/sdk/vercel
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages/shared/sdk-server-edge",
"packages/sdk/server-node",
"packages/sdk/cloudflare",
"packages/sdk/cloudflare/example"
"packages/sdk/cloudflare/example",
"packages/sdk/vercel"
],
"private": true,
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/vercel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

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).
62 changes: 62 additions & 0 deletions packages/sdk/vercel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# LaunchDarkly Vercel Edge SDK

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).

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

## Install

```shell
npm i @launchdarkly/vercel-server-sdk
```

or yarn:

```shell
yarn add -D @launchdarkly/vercel-server-sdk
```

## Quickstart

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:

```typescript
import init from '@launchdarkly/vercel-server-sdk'
import { createClient } from '@vercel/edge-config'

const edgeClient = createClient(process.env.EDGE_CONFIG)
const ldClient = init('YOUR CLIENT-SIDE SDK KEY', edgeClient);

await ldClient.waitForInitialization()
const ldContext = {
kind: 'org',
key: 'my-org-key',
someAttribute: 'my-attribute-value'
}
const flagValue = await ldClient.variation('my-flag', ldContext, true);
```

To learn more, head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/sdk/server-side/vercel).

## Developing this SDK

```shell
# at js-core repo root
yarn && yarn build && cd packages/sdk/vercel
# run tests
yarn test
```

## About LaunchDarkly

- 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:
- 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.
- 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?).
- 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.
- 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.
- 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.
- Explore LaunchDarkly
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
9 changes: 9 additions & 0 deletions packages/sdk/vercel/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"transform": { "^.+\\.ts?$": "ts-jest" },
"testMatch": ["**/*.test.ts?(x)"],
"testPathIgnorePatterns": ["node_modules", "example", "dist"],
"modulePathIgnorePatterns": ["dist"],
"testEnvironment": "node",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"collectCoverageFrom": ["src/**/*.ts"]
}
58 changes: 58 additions & 0 deletions packages/sdk/vercel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@launchdarkly/vercel-server-sdk",
"version": "0.1.0",
"description": "LaunchDarkly Server-Side SDK for Vercel Edge",
"packageManager": "[email protected]",
"keywords": [
"launchdarkly",
"vercel",
"edge"
],
"type": "module",
"exports": {
"require": "./dist/cjs/src/index.js",
"import": "./dist/esm/src/index.js",
"types": "./dist/esm/src/index.d.ts"
},
"main": "./dist/cjs/src/index.js",
"types": "./dist/cjs/src/index.d.ts",
"files": [
"/dist"
],
"scripts": {
"doc": "../../../scripts/build-doc.sh .",
"build": "../../../scripts/build-package.sh",
"tsw": "yarn tsc --watch",
"start": "yarn tsw",
"lint": "eslint . --ext .ts",
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)'",
"test": "jest --ci --runInBand",
"check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc"
},
"dependencies": {
"@launchdarkly/js-server-sdk-common": "^0.2.0",
"@launchdarkly/js-server-sdk-common-edge": "0.0.2",
"crypto-js": "^4.1.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/jest": "^29.5.0",
"@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@vercel/edge-config": "^0.1.7",
"eslint": "^8.37.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"launchdarkly-js-test-helpers": "^2.2.0",
"prettier": "^2.8.7",
"ts-jest": "^29.1.0",
"typedoc": "0.23.26",
"typescript": "^5.0.3"
}
}
22 changes: 22 additions & 0 deletions packages/sdk/vercel/src/createPlatformInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Info, PlatformData, SdkData } from '@launchdarkly/js-server-sdk-common-edge';

import packageJson from '../package.json';

class VercelPlatformInfo implements Info {
platformData(): PlatformData {
return {
name: 'Vercel Edge',
};
}

sdkData(): SdkData {
return {
name: packageJson.name,
version: packageJson.version,
};
}
}

const createPlatformInfo = () => new VercelPlatformInfo();

export default createPlatformInfo;
53 changes: 53 additions & 0 deletions packages/sdk/vercel/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This is the API reference for the Vercel LaunchDarkly SDK.
*
* In typical usage, you will call {@link init} once at startup time to obtain an instance of
* {@link LDClient}, which provides access to all of the SDK's functionality.
*
* For more information, see the SDK reference guide.
*
* @packageDocumentation
*/
import type { EdgeConfigClient } from '@vercel/edge-config';
import {
BasicLogger,
init as initEdge,
LDClient,
LDOptions,
} from '@launchdarkly/js-server-sdk-common-edge';
import VercelFeatureStore from './vercelFeatureStore';
import createPlatformInfo from './createPlatformInfo';

export * from '@launchdarkly/js-server-sdk-common-edge';

export type { LDClient };

/**
* Creates an instance of the Vercel LaunchDarkly client.
*
* Applications should instantiate a single instance for the lifetime of the worker.
* The client will begin attempting to connect to the configured Vercel Edge Config as
* soon as it is created. To determine when it is ready to use, call {@link LDClient.waitForInitialization}.
*
* **Important:** Do **not** try to instantiate `LDClient` with its constructor
* (`new LDClient()/new LDClientImpl()/new LDClient()`); the SDK does not currently support
* this.
*
* @param edgeConfig
* The Vercel Edge Config client configured for LaunchDarkly.
* @param sdkKey
* The client side SDK key. This is only used to query the edgeConfig above,
* not to connect with LaunchDarkly servers.
* @param options
* Optional configuration settings. The only supported option is logger.
* @return
* The new {@link LDClient} instance.
*/
export const init = (sdkKey: string, edgeConfig: EdgeConfigClient, options: LDOptions = {}) => {
const logger = options.logger ?? BasicLogger.get();
return initEdge(sdkKey, createPlatformInfo(), {
featureStore: new VercelFeatureStore(edgeConfig, sdkKey, logger),
logger,
...options,
});
};
10 changes: 10 additions & 0 deletions packages/sdk/vercel/src/utils/mockEdge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EdgeConfigClient } from '@vercel/edge-config';

const mockEdge: EdgeConfigClient = {
get: jest.fn(),
getAll: jest.fn(),
digest: jest.fn(),
has: jest.fn(),
};

export default mockEdge;
50 changes: 50 additions & 0 deletions packages/sdk/vercel/src/utils/testData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"flags": {
"testFlag1": {
"key": "testFlag1",
"on": false,
"prerequisites": [],
"targets": [],
"rules": [],
"fallthrough": {
"variation": 0
},
"offVariation": 1,
"variations": [true, false],
"clientSideAvailability": {
"usingMobileKey": true,
"usingEnvironmentId": true
},
"clientSide": true,
"salt": "aef830243d6640d0a973be89988e008d",
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"deleted": false
},
"testFlag2": {
"key": "testFlag2",
"on": false,
"prerequisites": [],
"targets": [],
"rules": [],
"fallthrough": {
"variation": 0
},
"offVariation": 1,
"variations": [true, false],
"clientSideAvailability": {
"usingMobileKey": true,
"usingEnvironmentId": true
},
"clientSide": true,
"salt": "aef830243d6640d0a973be89988e008d",
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"deleted": false
}
}
}
Loading