@openfeature/server-sdk
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -84,7 +84,7 @@ "use strict"; | ||
var import_core2 = require("@openfeature/core"); | ||
var VariantFoundError = class extends import_core2.OpenFeatureError { | ||
var VariantFoundError = class _VariantFoundError extends import_core2.OpenFeatureError { | ||
code; | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, VariantFoundError.prototype); | ||
Object.setPrototypeOf(this, _VariantFoundError.prototype); | ||
this.name = "VariantFoundError"; | ||
@@ -200,3 +200,3 @@ this.code = import_core2.ErrorCode.GENERAL; | ||
var _globalThis = globalThis; | ||
var OpenFeatureAPI = class extends import_core6.OpenFeatureCommonAPI { | ||
var OpenFeatureAPI = class _OpenFeatureAPI extends import_core6.OpenFeatureCommonAPI { | ||
_events = new OpenFeatureEventEmitter(); | ||
@@ -219,3 +219,3 @@ _defaultProvider = NOOP_PROVIDER; | ||
} | ||
const instance = new OpenFeatureAPI(); | ||
const instance = new _OpenFeatureAPI(); | ||
_globalThis[GLOBAL_OPENFEATURE_API_KEY] = instance; | ||
@@ -231,11 +231,11 @@ return instance; | ||
} | ||
getClient(nameOrContext, versionOrContext, contextOrUndefined) { | ||
const name = (0, import_core6.stringOrUndefined)(nameOrContext); | ||
getClient(domainOrContext, versionOrContext, contextOrUndefined) { | ||
const domain = (0, import_core6.stringOrUndefined)(domainOrContext); | ||
const version = (0, import_core6.stringOrUndefined)(versionOrContext); | ||
const context = (0, import_core6.objectOrUndefined)(nameOrContext) ?? (0, import_core6.objectOrUndefined)(versionOrContext) ?? (0, import_core6.objectOrUndefined)(contextOrUndefined); | ||
const context = (0, import_core6.objectOrUndefined)(domainOrContext) ?? (0, import_core6.objectOrUndefined)(versionOrContext) ?? (0, import_core6.objectOrUndefined)(contextOrUndefined); | ||
return new OpenFeatureClient( | ||
() => this.getProviderForClient(name), | ||
() => this.buildAndCacheEventEmitterForClient(name), | ||
() => this.getProviderForClient(domain), | ||
() => this.buildAndCacheEventEmitterForClient(domain), | ||
() => this._logger, | ||
{ name, version }, | ||
{ domain, version }, | ||
context | ||
@@ -292,3 +292,5 @@ ); | ||
return { | ||
name: this.options.name, | ||
// Use domain if name is not provided | ||
name: this.options.domain ?? this.options.name, | ||
domain: this.options.domain ?? this.options.name, | ||
version: this.options.version, | ||
@@ -303,3 +305,7 @@ providerMetadata: this.providerAccessor().metadata | ||
try { | ||
handler({ clientName: this.metadata.name, providerName: this._provider.metadata.name }); | ||
handler({ | ||
clientName: this.metadata.name, | ||
domain: this.metadata.domain, | ||
providerName: this._provider.metadata.name | ||
}); | ||
} catch (err) { | ||
@@ -494,4 +500,5 @@ this._logger?.error("Error running event handler:", err); | ||
OpenFeatureEventEmitter, | ||
ProviderEvents | ||
ProviderEvents, | ||
...require("@openfeature/core") | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -51,7 +51,7 @@ // src/client/open-feature-client.ts | ||
import { ErrorCode, OpenFeatureError } from "@openfeature/core"; | ||
var VariantFoundError = class extends OpenFeatureError { | ||
var VariantFoundError = class _VariantFoundError extends OpenFeatureError { | ||
code; | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, VariantFoundError.prototype); | ||
Object.setPrototypeOf(this, _VariantFoundError.prototype); | ||
this.name = "VariantFoundError"; | ||
@@ -171,3 +171,3 @@ this.code = ErrorCode.GENERAL; | ||
var _globalThis = globalThis; | ||
var OpenFeatureAPI = class extends OpenFeatureCommonAPI { | ||
var OpenFeatureAPI = class _OpenFeatureAPI extends OpenFeatureCommonAPI { | ||
_events = new OpenFeatureEventEmitter(); | ||
@@ -190,3 +190,3 @@ _defaultProvider = NOOP_PROVIDER; | ||
} | ||
const instance = new OpenFeatureAPI(); | ||
const instance = new _OpenFeatureAPI(); | ||
_globalThis[GLOBAL_OPENFEATURE_API_KEY] = instance; | ||
@@ -202,11 +202,11 @@ return instance; | ||
} | ||
getClient(nameOrContext, versionOrContext, contextOrUndefined) { | ||
const name = stringOrUndefined(nameOrContext); | ||
getClient(domainOrContext, versionOrContext, contextOrUndefined) { | ||
const domain = stringOrUndefined(domainOrContext); | ||
const version = stringOrUndefined(versionOrContext); | ||
const context = objectOrUndefined(nameOrContext) ?? objectOrUndefined(versionOrContext) ?? objectOrUndefined(contextOrUndefined); | ||
const context = objectOrUndefined(domainOrContext) ?? objectOrUndefined(versionOrContext) ?? objectOrUndefined(contextOrUndefined); | ||
return new OpenFeatureClient( | ||
() => this.getProviderForClient(name), | ||
() => this.buildAndCacheEventEmitterForClient(name), | ||
() => this.getProviderForClient(domain), | ||
() => this.buildAndCacheEventEmitterForClient(domain), | ||
() => this._logger, | ||
{ name, version }, | ||
{ domain, version }, | ||
context | ||
@@ -263,3 +263,5 @@ ); | ||
return { | ||
name: this.options.name, | ||
// Use domain if name is not provided | ||
name: this.options.domain ?? this.options.name, | ||
domain: this.options.domain ?? this.options.name, | ||
version: this.options.version, | ||
@@ -274,3 +276,7 @@ providerMetadata: this.providerAccessor().metadata | ||
try { | ||
handler({ clientName: this.metadata.name, providerName: this._provider.metadata.name }); | ||
handler({ | ||
clientName: this.metadata.name, | ||
domain: this.metadata.domain, | ||
providerName: this._provider.metadata.name | ||
}); | ||
} catch (err) { | ||
@@ -277,0 +283,0 @@ this._logger?.error("Error running event handler:", err); |
@@ -230,3 +230,7 @@ import { BaseHook, FlagValue, EvaluationContext, HookHints, EvaluationDetails, JsonValue, EvaluationLifeCycle, ManageContext, ManageLogger, Eventing, ClientMetadata, GenericEventEmitter, ServerProviderEvents, CommonProvider, Logger, ResolutionDetails, ProviderStatus, EventHandler, OpenFeatureCommonAPI } from '@openfeature/core'; | ||
type OpenFeatureClientOptions = { | ||
/** | ||
* @deprecated Use `domain` instead. | ||
*/ | ||
name?: string; | ||
domain?: string; | ||
version?: string; | ||
@@ -337,7 +341,7 @@ }; | ||
/** | ||
* A factory function for creating new unnamed OpenFeature clients. Clients can contain | ||
* their own state (e.g. logger, hook, context). Multiple clients can be used | ||
* to segment feature flag configuration. | ||
* A factory function for creating new domainless OpenFeature clients. | ||
* Clients can contain their own state (e.g. logger, hook, context). | ||
* Multiple clients can be used to segment feature flag configuration. | ||
* | ||
* All unnamed clients use the same provider set via {@link this.setProvider setProvider}. | ||
* All domainless or unbound clients use the default provider set via {@link this.setProvider setProvider}. | ||
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations | ||
@@ -348,21 +352,21 @@ * @returns {Client} OpenFeature Client | ||
/** | ||
* A factory function for creating new named OpenFeature clients. Clients can contain | ||
* their own state (e.g. logger, hook, context). Multiple clients can be used | ||
* to segment feature flag configuration. | ||
* A factory function for creating new domain scoped OpenFeature clients. | ||
* Clients can contain their own state (e.g. logger, hook, context). | ||
* Multiple clients can be used to segment feature flag configuration. | ||
* | ||
* If there is already a provider bound to this name via {@link this.setProvider setProvider}, this provider will be used. | ||
* Otherwise, the default provider is used until a provider is assigned to that name. | ||
* @param {string} name The name of the client | ||
* If there is already a provider bound to this domain via {@link this.setProvider setProvider}, this provider will be used. | ||
* Otherwise, the default provider is used until a provider is assigned to that domain. | ||
* @param {string} domain An identifier which logically binds clients with providers | ||
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations | ||
* @returns {Client} OpenFeature Client | ||
*/ | ||
getClient(name: string, context?: EvaluationContext): Client; | ||
getClient(domain: string, context?: EvaluationContext): Client; | ||
/** | ||
* A factory function for creating new named OpenFeature clients. Clients can contain | ||
* their own state (e.g. logger, hook, context). Multiple clients can be used | ||
* to segment feature flag configuration. | ||
* A factory function for creating new domain scoped OpenFeature clients. | ||
* Clients can contain their own state (e.g. logger, hook, context). | ||
* Multiple clients can be used to segment feature flag configuration. | ||
* | ||
* If there is already a provider bound to this name via {@link this.setProvider setProvider}, this provider will be used. | ||
* Otherwise, the default provider is used until a provider is assigned to that name. | ||
* @param {string} name The name of the client | ||
* If there is already a provider bound to this domain via {@link this.setProvider setProvider}, this provider will be used. | ||
* Otherwise, the default provider is used until a provider is assigned to that domain. | ||
* @param {string} domain An identifier which logically binds clients with providers | ||
* @param {string} version The version of the client (only used for metadata) | ||
@@ -372,3 +376,3 @@ * @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations | ||
*/ | ||
getClient(name: string, version: string, context?: EvaluationContext): Client; | ||
getClient(domain: string, version: string, context?: EvaluationContext): Client; | ||
/** | ||
@@ -375,0 +379,0 @@ * Clears all registered providers and resets the default provider. |
{ | ||
"name": "@openfeature/server-sdk", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "OpenFeature SDK for JavaScript", | ||
@@ -51,7 +51,7 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"@openfeature/core": "0.0.25" | ||
"@openfeature/core": "0.0.26" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "0.0.25" | ||
"@openfeature/core": "0.0.26" | ||
} | ||
} |
@@ -19,4 +19,4 @@ <!-- markdownlint-disable MD033 --> | ||
<!-- x-release-please-start-version --> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/server-sdk-v1.11.0"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.11.0&color=blue&style=for-the-badge" /> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/server-sdk-v1.12.0"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.12.0&color=blue&style=for-the-badge" /> | ||
</a> | ||
@@ -90,12 +90,12 @@ <!-- x-release-please-end --> | ||
| Status | Features | Description | | ||
| ------ | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | ||
| ✅ | [Providers](#providers) | Integrate with a commercial, open source, or in-house feature management tool. | | ||
| ✅ | [Targeting](#targeting) | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). | | ||
| ✅ | [Hooks](#hooks) | Add functionality to various stages of the flag evaluation life-cycle. | | ||
| ✅ | [Logging](#logging) | Integrate with popular logging packages. | | ||
| ✅ | [Named clients](#named-clients) | Utilize multiple providers in a single application. | | ||
| ✅ | [Eventing](#eventing) | React to state changes in the provider or flag management system. | | ||
| ✅ | [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. | | ||
| ✅ | [Extending](#extending) | Extend OpenFeature with custom providers and hooks. | | ||
| Status | Features | Description | | ||
| ------ | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | ||
| ✅ | [Providers](#providers) | Integrate with a commercial, open source, or in-house feature management tool. | | ||
| ✅ | [Targeting](#targeting) | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). | | ||
| ✅ | [Hooks](#hooks) | Add functionality to various stages of the flag evaluation life-cycle. | | ||
| ✅ | [Logging](#logging) | Integrate with popular logging packages. | | ||
| ✅ | [Domains](#domains) | Logically bind clients with providers. | | ||
| ✅ | [Eventing](#eventing) | React to state changes in the provider or flag management system. | | ||
| ✅ | [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. | | ||
| ✅ | [Extending](#extending) | Extend OpenFeature with custom providers and hooks. | | ||
@@ -131,3 +131,3 @@ <sub>Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub> | ||
In some situations, it may be beneficial to register multiple providers in the same application. | ||
This is possible using [named clients](#named-clients), which is covered in more details below. | ||
This is possible using [domains](#domains), which is covered in more details below. | ||
@@ -160,3 +160,3 @@ ### Targeting | ||
[Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle | ||
[Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle. | ||
Look [here](https://openfeature.dev/ecosystem/?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Hook&instant_search%5BrefinementList%5D%5Bcategory%5D%5B0%5D=Server-side&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=JavaScript) for a complete list of available hooks. | ||
@@ -183,3 +183,3 @@ If the hook you're looking for hasn't been created yet, see the [develop a hook](#develop-a-hook) section to learn how to build it yourself. | ||
The JS SDK will log warning and errors to the console by default. | ||
The Node.JS SDK will log warnings and errors to the console by default. | ||
This behavior can be overridden by passing a custom logger either globally or per client. | ||
@@ -202,7 +202,7 @@ A custom logger must implement the [Logger interface](../shared/src/logger/logger.ts). | ||
### Named clients | ||
### Domains | ||
Clients can be given a name. | ||
A name is a logical identifier which can be used to associate clients with a particular provider. | ||
If a name has no associated provider, the global provider is used. | ||
Clients can be assigned to a domain. | ||
A domain is a logical identifier which can be used to associate clients with a particular provider. | ||
If a domain has no associated provider, the default provider is used. | ||
@@ -225,12 +225,12 @@ ```ts | ||
OpenFeature.setProvider(InMemoryProvider(myFlags)); | ||
// Registering a named provider | ||
OpenFeature.setProvider("otherClient", new InMemoryProvider(someOtherFlags)); | ||
// Registering a provider to a domain | ||
OpenFeature.setProvider("my-domain", new InMemoryProvider(someOtherFlags)); | ||
// A Client backed by default provider | ||
// A Client bound to the default provider | ||
const clientWithDefault = OpenFeature.getClient(); | ||
// A Client backed by NewCachedProvider | ||
const clientForCache = OpenFeature.getClient("otherClient"); | ||
// A Client bound to the InMemoryProvider provider | ||
const domainScopedClient = OpenFeature.getClient("my-domain"); | ||
``` | ||
Named providers can be set in an awaitable or synchronous way. | ||
Domains can be defined on a provider during registration. | ||
For more details, please refer to the [providers](#providers) section. | ||
@@ -237,0 +237,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152555
1315