Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openfeature/js-sdk

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openfeature/js-sdk - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/types/client.d.ts
import { Client, ClientMetadata, EvaluationContext, EvaluationDetails, FlagEvaluationOptions, FlagValue, Hook, JsonValue, Logger, Provider } from './types';
declare type OpenFeatureClientOptions = {
type OpenFeatureClientOptions = {
name?: string;

@@ -4,0 +4,0 @@ version?: string;

@@ -1,14 +0,14 @@

export declare type PrimitiveValue = null | boolean | string | number;
export declare type JsonObject = {
export type PrimitiveValue = null | boolean | string | number;
export type JsonObject = {
[key: string]: JsonValue;
};
export declare type JsonArray = JsonValue[];
export type JsonArray = JsonValue[];
/**
* Represents a JSON node value.
*/
export declare type JsonValue = PrimitiveValue | JsonObject | JsonArray;
export type JsonValue = PrimitiveValue | JsonObject | JsonArray;
/**
* Represents a JSON node value, or Date.
*/
export declare type EvaluationContextValue = PrimitiveValue | Date | {
export type EvaluationContextValue = PrimitiveValue | Date | {
[key: string]: EvaluationContextValue;

@@ -19,3 +19,3 @@ } | EvaluationContextValue[];

*/
export declare type EvaluationContext = {
export type EvaluationContext = {
/**

@@ -28,4 +28,4 @@ * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.

} & Record<string, EvaluationContextValue>;
export declare type FlagValue = boolean | string | number | JsonValue;
export declare type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
export type FlagValue = boolean | string | number | JsonValue;
export type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
export interface FlagEvaluationOptions {

@@ -225,4 +225,4 @@ hooks?: Hook[];

}
export declare type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
export declare type ResolutionDetails<U> = {
export type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
export type ResolutionDetails<U> = {
value: U;

@@ -234,3 +234,3 @@ variant?: string;

};
export declare type EvaluationDetails<T extends FlagValue> = {
export type EvaluationDetails<T extends FlagValue> = {
flagKey: string;

@@ -320,3 +320,3 @@ } & ResolutionDetails<T>;

}
export declare type HookHints = Readonly<Record<string, unknown>>;
export type HookHints = Readonly<Record<string, unknown>>;
interface Metadata {

@@ -382,3 +382,3 @@ }

*/
export declare type TransactionContext = EvaluationContext;
export type TransactionContext = EvaluationContext;
interface ManageTransactionContextPropagator<T> extends TransactionContextPropagator {

@@ -385,0 +385,0 @@ /**

{
"name": "@openfeature/js-sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "OpenFeature SDK for JavaScript",

@@ -41,2 +41,3 @@ "main": "./dist/cjs/index.js",

"exports": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",

@@ -47,8 +48,8 @@ "require": "./dist/cjs/index.js",

"devDependencies": {
"@openfeature/flagd-provider": "~0.6.0",
"@types/jest": "^28.1.4",
"@openfeature/flagd-provider": "~0.7.0",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.3",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"esbuild": "^0.15.1",
"esbuild": "^0.16.0",
"eslint": "^8.14.0",

@@ -61,7 +62,7 @@ "eslint-config-prettier": "^8.5.0",

"eslint-plugin-jsdoc": "^39.3.6",
"jest": "^28.1.3",
"jest": "^29.0.0",
"jest-cucumber": "^3.0.1",
"jest-junit": "^14.0.0",
"jest-junit": "^15.0.0",
"prettier": "^2.6.2",
"ts-jest": "^28.0.8",
"ts-jest": "^29.0.0",
"ts-node": "^10.8.2",

@@ -68,0 +69,0 @@ "typedoc": "^0.23.16",

@@ -10,7 +10,17 @@ # OpenFeature SDK for JavaScript

This is the JavaScript implementation of [OpenFeature](https://openfeature.dev), a vendor-agnostic abstraction library for evaluating feature flags.
<p align="center">
<strong>
<a href="https://docs.openfeature.dev/docs/tutorials/getting-started/node">Getting Started<a/>
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
<a href="open-feature.github.io/js-sdk">API Documentation<a/>
</strong>
</p>
---
This is the JavaScript implementation of [OpenFeature][openfeature-website], a vendor-agnostic abstraction library for evaluating feature flags.
We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.
**This library is intended to be used in server-side contexts and has only experimental support for web usage.**
> 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].

@@ -31,2 +41,4 @@ ## Installation

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.
```typescript

@@ -60,4 +72,44 @@ import { OpenFeature } from '@openfeature/js-sdk';

A list of available providers can be found [here][server-side-artifacts].
For complete documentation, visit: https://docs.openfeature.dev/docs/category/concepts
## Hooks
Implement your own hook by conforming to the [Hook interface][hook-interface].
All of the hook stages (before, after, error, and finally) are optional.
```typescript
import { OpenFeature, Hook, HookContext } from '@openfeature/js-sdk';
// Example hook that logs if an error occurs during flag evaluation
export class GlobalDebugHook implements Hook {
after(hookContext: HookContext, err: Error) {
console.log('hook context', hookContext);
console.error(err);
}
}
```
Register the hook at global, client, or invocation level.
```typescript
import { OpenFeature } from '@openfeature/js-sdk';
// This hook used is used for example purposes
import { GlobalDebugHook, ClientDebugHook, InvocationDebugHook } from './debug-hook';
// A global hook will run on every flag evaluation
OpenFeature.addHooks(new GlobalDebugHook());
const client = OpenFeature.getClient('my-app');
// A client hook will run on every flag evaluation executed by this client
client.addHooks(new ClientDebugHook());
// An invocation hook will only run on the registred flag evaluation method
const boolValue = await client.getBooleanValue('boolFlag', false, {}, { hooks: [new InvocationDebugHook()] });
```
A list of available hooks can be found [here][server-side-artifacts].
## Contributing

@@ -67,5 +119,5 @@

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.
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.
Thanks so much to our contributors.
### Thanks to everyone that has already contributed

@@ -81,1 +133,6 @@ <a href="https://github.com/open-feature/js-sdk/graphs/contributors">

[Apache License 2.0](LICENSE)
[openfeature-website]: https://openfeature.dev
[server-side-artifacts]: https://docs.openfeature.dev/docs/reference/technologies/server/javascript
[hook-interface]: https://open-feature.github.io/js-sdk/interfaces/Hook.html
[client-side-github-issue]: https://github.com/open-feature/spec/issues/167
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc