Skip to content

Commit 9fbb2bd

Browse files
authored
docs: improved the readme (#352)
1 parent 4d4fca4 commit 9fbb2bd

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

README.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
[![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)
88
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6594/badge)](https://bestpractices.coreinfrastructure.org/projects/6594)
99

10-
This is the JavaScript implementation of [OpenFeature](https://openfeature.dev), a vendor-agnostic abstraction library for evaluating feature flags.
10+
<p align="center">
11+
<strong>
12+
<a href="https://docs.openfeature.dev/docs/tutorials/getting-started/node">Getting Started<a/>
13+
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
14+
<a href="open-feature.github.io/js-sdk">API Documentation<a/>
15+
</strong>
16+
</p>
17+
18+
---
19+
20+
This is the JavaScript implementation of [OpenFeature][openfeature-website], a vendor-agnostic abstraction library for evaluating feature flags.
1121

1222
We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.
1323

14-
**This library is intended to be used in server-side contexts and has only experimental support for web usage.**
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].
1525
1626
## Installation
1727

@@ -27,6 +37,8 @@ yarn add @openfeature/js-sdk
2737

2838
## Usage
2939

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+
3042
```typescript
3143
import { OpenFeature } from '@openfeature/js-sdk';
3244

@@ -55,15 +67,55 @@ const context: EvaluationContext = {
5567
const contextAwareValue = await client.getBooleanValue('boolFlag', false, context);
5668
```
5769

70+
A list of available providers can be found [here][server-side-artifacts].
71+
5872
For complete documentation, visit: https://docs.openfeature.dev/docs/category/concepts
5973

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].
111+
60112
## Contributing
61113

62114
See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to the OpenFeature project.
63115

64-
Our community meetings are held regularly and open to everyone. Check the [OpenFeature community calendar](https://calendar.google.com/calendar/u/0?cid=MHVhN2kxaGl2NWRoMThiMjd0b2FoNjM2NDRAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) for specific dates and for the Zoom meeting links.
116+
Our community meetings are held regularly and open to everyone. Check the [OpenFeature community calendar](https://calendar.google.com/calendar/u/0?cid=MHVhN2kxaGl2NWRoMThiMjd0b2FoNjM2NDRAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) for specific dates and the Zoom meeting links.
65117

66-
Thanks so much to our contributors.
118+
### Thanks to everyone that has already contributed
67119

68120
<a href="https://github.com/open-feature/js-sdk/graphs/contributors">
69121
<img src="https://contrib.rocks/image?repo=open-feature/js-sdk" />
@@ -74,3 +126,8 @@ Made with [contrib.rocks](https://contrib.rocks).
74126
## License
75127

76128
[Apache License 2.0](LICENSE)
129+
130+
[openfeature-website]: https://openfeature.dev
131+
[server-side-artifacts]: https://docs.openfeature.dev/docs/reference/technologies/server/javascript
132+
[hook-interface]: https://open-feature.github.io/js-sdk/interfaces/Hook.html
133+
[client-side-github-issue]: https://github.com/open-feature/spec/issues/167

0 commit comments

Comments
 (0)