Skip to content

Commit 30b822e

Browse files
authored
chore: Scaffold browser SDK project. (#555)
For now I am using Vite to build. If we encounter problems with this we can move to a rollup based build like we are using in other projects. Vite is easier to use and is reasonably popular, so I think it is a good starting point. Currently all tests in the monorepo use jest, so this continues to use jest. We may want to consider, in the future, if we want to move to vitest if it supports everything we need. This would make the testing configuration simpler.
1 parent 5ecdf31 commit 30b822e

File tree

17 files changed

+281
-1
lines changed

17 files changed

+281
-1
lines changed

.github/workflows/browser.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: sdk/browser
2+
3+
on:
4+
push:
5+
branches: [main, 'feat/**']
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main, 'feat/**']
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-browser:
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
# Node versions to run on.
20+
version: [18, 21]
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.version }}
27+
registry-url: 'https://registry.npmjs.org'
28+
- id: shared
29+
name: Shared CI Steps
30+
uses: ./actions/ci
31+
with:
32+
workspace_name: '@launchdarkly/js-client-sdk'
33+
workspace_path: packages/sdk/browser

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
- packages/store/node-server-sdk-redis
2020
- packages/store/node-server-sdk-dynamodb
2121
- packages/telemetry/node-server-sdk-otel
22+
- packages/sdk/browser
2223
name: Publish Documentation
2324
jobs:
2425
build-publish:

.github/workflows/manual-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ on:
3232
- packages/store/node-server-sdk-dynamodb
3333
- packages/telemetry/node-server-sdk-otel
3434
- packages/tooling/jest
35+
- packages/sdk/browser
3536
prerelease:
3637
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
3738
type: boolean

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs.
1414
| [@launchdarkly/vercel-server-sdk](packages/sdk/vercel/README.md) | [![NPM][sdk-vercel-npm-badge]][sdk-vercel-npm-link] | [Vercel][package-sdk-vercel-issues] | [![Actions Status][sdk-vercel-ci-badge]][sdk-vercel-ci] |
1515
| [@launchdarkly/react-native-client-sdk](packages/sdk/react-native/README.md) | [![NPM][sdk-react-native-npm-badge]][sdk-react-native-npm-link] | [React-Native][package-sdk-react-native-issues] | [![Actions Status][sdk-react-native-ci-badge]][sdk-react-native-ci] |
1616

17+
<!--
18+
TODO: Add row once @launchdarkly/js-client-sdk has been published.
19+
| [@launchdarkly/js-client-sdk](packages/sdk/browser/README.md) | [![NPM][sdk-browser-npm-badge]][sdk-browser-npm-link] | [Browser][package-sdk-browser-issues] | [![Actions Status][sdk-browser-ci-badge]][sdk-browser-ci] |
20+
-->
21+
1722
| Shared packages | npm | issues | tests |
1823
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------- |
1924
| [@launchdarkly/js-sdk-common](packages/shared/common/README.md) | [![NPM][common-npm-badge]][common-npm-link] | [Common][package-shared-common-issues] | [![Actions Status][shared-common-ci-badge]][shared-common-ci] |
@@ -169,3 +174,13 @@ We encourage pull requests and other contributions from the community. Check out
169174
[node-otel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-otel.svg?style=flat-square
170175
[node-otel-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-otel
171176
[node-otel-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+telemetry%2Fnode-server-sdk-otel%22+
177+
[//]: # 'sdk/browser'
178+
[sdk-browser-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml/badge.svg
179+
[sdk-browser-ci]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml
180+
[sdk-browser-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/js-client-sdk.svg?style=flat-square
181+
[sdk-browser-npm-link]: https://www.npmjs.com/package/@launchdarkly/js-client-sdk
182+
[sdk-browser-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
183+
[sdk-browser-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/
184+
[sdk-browser-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/js-client-sdk.svg?style=flat-square
185+
[sdk-browser-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/js-client-sdk.svg?style=flat-square
186+
[package-sdk-browser-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+sdk%2Fbrowser%22+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"packages/store/node-server-sdk-redis",
2323
"packages/store/node-server-sdk-dynamodb",
2424
"packages/telemetry/node-server-sdk-otel",
25-
"packages/tooling/jest"
25+
"packages/tooling/jest",
26+
"packages/sdk/browser"
2627
],
2728
"private": true,
2829
"scripts": {

packages/sdk/browser/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2024 Catamorphic, Co.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

packages/sdk/browser/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# LaunchDarkly JavaScript SDK for Browsers
2+
3+
<!--
4+
[![NPM][browser-sdk-npm-badge]][browser-sdk-npm-link]
5+
[![Actions Status][browser-sdk-ci-badge]][browser-sdk-ci]
6+
[![Documentation][browser-sdk-ghp-badge]][browser-sdk-ghp-link]
7+
[![NPM][browser-sdk-dm-badge]][browser-sdk-npm-link]
8+
[![NPM][browser-sdk-dt-badge]][browser-sdk-npm-link]
9+
-->
10+
11+
> [!CAUTION]
12+
> This library is a beta version and should not be considered ready for production use while this message is visible.
13+
14+
<!--
15+
## Install
16+
17+
```shell
18+
# npm
19+
npm i @launchdarkly/js-client-sdk
20+
21+
# yarn
22+
yarn add -D @launchdarkly/js-client-sdk
23+
```
24+
-->
25+
26+
## Getting started
27+
28+
Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/client-side/javascript#getting-started) for instructions on getting started with using the SDK.
29+
30+
Note: _If you are using JavaScript in a non-browser environment, please check our other SDK packages in [js-core](https://github.com/launchdarkly/js-core)_
31+
Please note that the JavaScript SDK has two special requirements in terms of your LaunchDarkly environment. First, in terms of the credentials for your environment that appear on your [Account Settings](https://app.launchdarkly.com/settings/projects) dashboard, the JavaScript SDK uses the "Client-side ID"-- not the "SDK key" or the "Mobile key". Second, for any feature flag that you will be using in JavaScript code, you must check the "Make this flag available to client-side SDKs" box on that flag's Settings page.
32+
33+
## Verifying SDK build provenance with the SLSA framework
34+
35+
LaunchDarkly uses the [SLSA framework](https://slsa.dev/spec/v1.0/about) (Supply-chain Levels for Software Artifacts) to help developers make their supply chain more secure by ensuring the authenticity and build integrity of our published SDK packages. To learn more, see the [provenance guide](PROVENANCE.md).
36+
37+
## About LaunchDarkly
38+
39+
- 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:
40+
- 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.
41+
- 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?).
42+
- 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.
43+
- 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).
44+
- Disable parts of your application to facilitate maintenance, without taking everything offline.
45+
- 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.
46+
- Explore LaunchDarkly
47+
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
48+
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
49+
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
50+
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
51+
52+
[browser-sdk-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml/badge.svg
53+
[browser-sdk-ci]: https://github.com/launchdarkly/js-core/actions/workflows/browser.yml
54+
[browser-sdk-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/js-client-sdk.svg?style=flat-square
55+
[browser-sdk-npm-link]: https://www.npmjs.com/package/@launchdarkly/js-client-sdk
56+
[browser-sdk-ghp-badge]: https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8
57+
[browser-sdk-ghp-link]: https://launchdarkly.github.io/js-core/packages/sdk/browser/docs/
58+
[browser-sdk-dm-badge]: https://img.shields.io/npm/dm/@launchdarkly/js-client-sdk.svg?style=flat-square
59+
[browser-sdk-dt-badge]: https://img.shields.io/npm/dt/@launchdarkly/js-client-sdk.svg?style=flat-square
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it('can run tests', () => {
2+
expect(true).toBe(true);
3+
});

packages/sdk/browser/package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@launchdarkly/js-client-sdk",
3+
"version": "0.0.0",
4+
"description": "LaunchDarkly SDK for JavaScript in Browsers",
5+
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/browser",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/launchdarkly/js-core.git"
9+
},
10+
"license": "Apache-2.0",
11+
"packageManager": "[email protected]",
12+
"keywords": [
13+
"launchdarkly",
14+
"feature flags",
15+
"feature toggles",
16+
"feature management",
17+
"sdk"
18+
],
19+
"exports": {
20+
"types": "./dist/src/index.d.ts",
21+
"require": "./dist/index.cjs.js",
22+
"import": "./dist/index.es.js"
23+
},
24+
"type": "module",
25+
"files": [
26+
"dist"
27+
],
28+
"scripts": {
29+
"clean": "rimraf dist",
30+
"build": "vite build",
31+
"lint": "eslint . --ext .ts,.tsx",
32+
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
33+
"test": "jest",
34+
"coverage": "yarn test --coverage",
35+
"check": "yarn prettier && yarn lint && yarn build && yarn test"
36+
},
37+
"dependencies": {
38+
"@launchdarkly/js-client-sdk-common": "1.5.0"
39+
},
40+
"devDependencies": {
41+
"@launchdarkly/private-js-mocks": "0.0.1",
42+
"@testing-library/react": "^14.1.2",
43+
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
44+
"@types/jest": "^29.5.11",
45+
"@typescript-eslint/eslint-plugin": "^6.20.0",
46+
"@typescript-eslint/parser": "^6.20.0",
47+
"eslint": "^8.45.0",
48+
"eslint-config-airbnb-base": "^15.0.0",
49+
"eslint-config-airbnb-typescript": "^17.1.0",
50+
"eslint-config-prettier": "^8.8.0",
51+
"eslint-plugin-import": "^2.27.5",
52+
"eslint-plugin-jest": "^27.6.3",
53+
"eslint-plugin-prettier": "^5.0.0",
54+
"jest": "^29.7.0",
55+
"prettier": "^3.0.0",
56+
"rimraf": "^5.0.5",
57+
"ts-jest": "^29.1.1",
58+
"typedoc": "0.25.0",
59+
"typescript": "^5.5.3",
60+
"vite": "^5.4.1",
61+
"vite-plugin-dts": "^4.0.3"
62+
}
63+
}

packages/sdk/browser/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function Hello() {
2+
// eslint-disable-next-line no-console
3+
console.log('HELLO');
4+
}

0 commit comments

Comments
 (0)