Skip to content

Commit 39c3b16

Browse files
toddbaertbeeme1mr
andauthored
chore: monorepo conversion + experimental web sdk (#353)
This PR transfroms this repo into a monorepo, with server (exsiting), client (new) and shared (new) packages. There are no tests yet for the client. Publishing _should_ work but is yet untested. The experimental web SDK will be published as `0.0.1-experimental` and features: - native browser events - "close" functionality (implemented in server as well) - async context setting - sync evaluation Though we want `close` and `events` in the server SDK, they are not implemented in this PR (though it would be very easy to do so and I've left TODO's about it). **There are no functional changes in the server SDK with this PR.** Here is a [direct link](https://github.com/open-feature/js-sdk/blob/experimental-web-sdk/README.md) to the README.md changes. **_I'm not expecting reviewers to go through this with a fine-toothed comb. Most of the changes are just establishing the monorepo, and the functional stuff in the new web-sdk is just experimental._**. Closes: #367 --------- Signed-off-by: Todd Baert <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
1 parent 87786d7 commit 39c3b16

Some content is hidden

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

60 files changed

+4006
-9621
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"browser": true,
44
"es2021": true
55
},
6+
"ignorePatterns": ["**/dist/**/*"],
67
"extends": [
78
"eslint:recommended",
89
"plugin:@typescript-eslint/recommended",

.github/workflows/release-please.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Publish to NPM
4343
env:
4444
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
45-
run: npm publish --access public
45+
run: npm run publish-all
4646

4747
- name: Build Docs
4848
run: npm run docs

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ typedoc
112112

113113
# IDE
114114
.idea
115+
116+
# license files copied from root
117+
packages/**/LICENSE

.release-please-manifest.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
".": "1.1.0"
2+
"packages/server": "1.1.0",
3+
"packages/client": "0.0.1-experimental",
4+
"packages/shared": "0.0.1"
35
}

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Install dependencies with `npm ci`. `npm install` will update the package-lock.j
1616

1717
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
1818

19+
### Modules
20+
21+
This repository uses [NPM workspaces](https://docs.npmjs.com/cli/v9/using-npm/workspaces) to establish a simple monorepo.
22+
Within the root project, there is one common project (`packages/shared`) which features common interfaces and code, consumed by the published modules (`packages/server` and `packages/client`). The shared module is bundled transparently into the published modules - it is not published itself. Changes in `packages/shared` will result in releases of the dependant modules via Release Please.
23+
1924
### Testing
2025

2126
Run tests with `npm test`.

README.md

+15-83
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
# OpenFeature SDK for JavaScript
1+
# OpenFeature JavaScript SDKs
22

33
[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
4+
[![Known Vulnerabilities](https://snyk.io/test/github/open-feature/js-sdk/badge.svg)](https://snyk.io/test/github/open-feature/js-sdk)
45
[![codecov](https://codecov.io/gh/open-feature/js-sdk/branch/main/graph/badge.svg?token=3DC5XOEHMY)](https://codecov.io/gh/open-feature/js-sdk)
6+
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6594/badge)](https://bestpractices.coreinfrastructure.org/projects/6594)
7+
8+
This repository contains the JavaScript implementations of [OpenFeature][openfeature-website], a vendor-agnostic abstraction library for evaluating feature flags.
9+
10+
We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.
11+
12+
## Server
13+
14+
---
15+
516
[![npm version](https://badge.fury.io/js/@openfeature%2Fjs-sdk.svg)](https://badge.fury.io/js/@openfeature%2Fjs-sdk)
6-
[![Known Vulnerabilities](https://snyk.io/test/github/open-feature/js-sdk/badge.svg)](https://snyk.io/test/github/open-feature/js-sdk)
717
[![v0.5.1](https://img.shields.io/static/v1?label=Specification&message=v0.5.1&color=yellow)](https://github.com/open-feature/spec/tree/v0.5.1)
8-
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6594/badge)](https://bestpractices.coreinfrastructure.org/projects/6594)
918

1019
<p align="center">
1120
<strong>
21+
<!-- TODO: add direct link to server module when published -->
1222
<a href="https://docs.openfeature.dev/docs/tutorials/getting-started/node">Getting Started<a/>
1323
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
1424
<a href="https://open-feature.github.io/js-sdk">API Documentation<a/>
@@ -17,13 +27,7 @@
1727

1828
---
1929

20-
This is the JavaScript implementation of [OpenFeature][openfeature-website], a vendor-agnostic abstraction library for evaluating feature flags.
21-
22-
We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.
23-
24-
> This library is intended to be used in server-side contexts and has only **experimental support** for web usage. Client-side support can be tracked [here][client-side-github-issue].
25-
26-
## Installation
30+
### Installation
2731

2832
```shell
2933
npm install @openfeature/js-sdk
@@ -35,79 +39,7 @@ or
3539
yarn add @openfeature/js-sdk
3640
```
3741

38-
## Usage
39-
40-
To configure the SDK you'll need to add a provider to the `OpenFeature` global signleton. From there, you can generate a `client` which is usable by your code. While you'll likely want a provider for your specific backend, we've provided a `NoopProvider`, which simply returns the default value.
41-
42-
```typescript
43-
import { OpenFeature } from '@openfeature/js-sdk';
44-
45-
// configure a provider
46-
OpenFeature.setProvider(new YourProviderOfChoice());
47-
48-
// create a client
49-
const client = OpenFeature.getClient('my-app');
50-
51-
// get a bool value
52-
const boolValue = await client.getBooleanValue('boolFlag', false);
53-
54-
// get a string value
55-
const stringValue = await client.getStringValue('stringFlag', 'default');
56-
57-
// get an numeric value
58-
const numberValue = await client.getNumberValue('intFlag', 1);
59-
60-
// get an object value
61-
const object = await client.getObjectValue<MyObject>('objectFlag', {});
62-
63-
// add a value to the invocation context
64-
const context: EvaluationContext = {
65-
myInvocationKey: 'myInvocationValue',
66-
};
67-
const contextAwareValue = await client.getBooleanValue('boolFlag', false, context);
68-
```
69-
70-
A list of available providers can be found [here][server-side-artifacts].
71-
72-
For complete documentation, visit: https://docs.openfeature.dev/docs/category/concepts
73-
74-
## Hooks
75-
76-
Implement your own hook by conforming to the [Hook interface][hook-interface].
77-
78-
All of the hook stages (before, after, error, and finally) are optional.
79-
80-
```typescript
81-
import { OpenFeature, Hook, HookContext } from '@openfeature/js-sdk';
82-
83-
// Example hook that logs if an error occurs during flag evaluation
84-
export class GlobalDebugHook implements Hook {
85-
after(hookContext: HookContext, err: Error) {
86-
console.log('hook context', hookContext);
87-
console.error(err);
88-
}
89-
}
90-
```
91-
92-
Register the hook at global, client, or invocation level.
93-
94-
```typescript
95-
import { OpenFeature } from '@openfeature/js-sdk';
96-
// This hook used is used for example purposes
97-
import { GlobalDebugHook, ClientDebugHook, InvocationDebugHook } from './debug-hook';
98-
99-
// A global hook will run on every flag evaluation
100-
OpenFeature.addHooks(new GlobalDebugHook());
101-
102-
const client = OpenFeature.getClient('my-app');
103-
// A client hook will run on every flag evaluation executed by this client
104-
client.addHooks(new ClientDebugHook());
105-
106-
// An invocation hook will only run on the registred flag evaluation method
107-
const boolValue = await client.getBooleanValue('boolFlag', false, {}, { hooks: [new InvocationDebugHook()] });
108-
```
109-
110-
A list of available hooks can be found [here][server-side-artifacts].
42+
See [README.md](./packages/server/README.md)
11143

11244
## Contributing
11345

jest.config.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,29 @@ export default {
106106

107107
// A preset that is used as a base for Jest's configuration
108108
preset: 'ts-jest',
109-
110109
// Run tests from one or more projects
111-
// projects: undefined,
110+
projects: [
111+
{
112+
displayName: 'server',
113+
testEnvironment: 'node',
114+
preset: 'ts-jest',
115+
testMatch: [
116+
'<rootDir>/packages/server/test/**/*.spec.ts'
117+
]
118+
},
119+
{
120+
displayName: 'server-e2e',
121+
testEnvironment: 'node',
122+
preset: 'ts-jest',
123+
testMatch: [
124+
'<rootDir>/packages/server/integration/**/*.spec.ts'
125+
],
126+
modulePathIgnorePatterns: [
127+
'.*/node-modules/'
128+
],
129+
setupFiles: ['<rootDir>/packages/server/integration/step-definitions/setup.ts'],
130+
}
131+
],
112132

113133
// Use this configuration option to add custom reporters to Jest
114134
// reporters: undefined,
@@ -126,10 +146,9 @@ export default {
126146
// restoreMocks: false,
127147

128148
// The root directory that Jest should scan for tests and modules within
129-
// rootDir: undefined,
149+
rootDir: './',
130150

131151
// A list of paths to directories that Jest should use to search for files in
132-
roots: ['<rootDir>/test'],
133152

134153
// Allows you to use a custom runner instead of Jest's default test runner
135154
// runner: "jest-runner",

0 commit comments

Comments
 (0)