@openfeature/web-sdk
Advanced tools
Comparing version 0.4.9 to 0.4.10
@@ -674,9 +674,15 @@ "use strict"; | ||
this._context = context; | ||
const providersWithoutContextOverride = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [, provider]) => { | ||
acc.push(provider); | ||
const defaultContextNameProviders = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [name, provider]) => { | ||
acc.push({ name, provider }); | ||
return acc; | ||
}, []); | ||
const allProviders = [this._defaultProvider, ...providersWithoutContextOverride]; | ||
const allProviders = [ | ||
// add in the default (no name) | ||
{ name: void 0, provider: this._defaultProvider }, | ||
...defaultContextNameProviders | ||
]; | ||
yield Promise.all( | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(void 0, provider, oldContext, context)) | ||
allProviders.map( | ||
(tuple) => this.runProviderContextChangeHandler(tuple.name, tuple.provider, oldContext, context) | ||
) | ||
); | ||
@@ -759,18 +765,19 @@ } | ||
return __async(this, null, function* () { | ||
var _a; | ||
var _a, _b, _c, _d, _e; | ||
const providerName = provider.metadata.name; | ||
return (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext).then(() => { | ||
var _a2; | ||
try { | ||
yield (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(import_core2.ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}); | ||
(_a2 = this._events) == null ? void 0 : _a2.emit(import_core2.ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}).catch((err) => { | ||
var _a2, _b; | ||
(_a2 = this._logger) == null ? void 0 : _a2.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
(_b = this._events) == null ? void 0 : _b.emit(import_core2.ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
} catch (err) { | ||
const error = err; | ||
const message = `Error running ${(_c = provider == null ? void 0 : provider.metadata) == null ? void 0 : _c.name}'s context change handler: ${error == null ? void 0 : error.message}`; | ||
(_d = this._logger) == null ? void 0 : _d.error(`${message}`, err); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
emitter == null ? void 0 : emitter.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message }); | ||
}); | ||
(_b = this._events) == null ? void 0 : _b.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
(_e = this._events) == null ? void 0 : _e.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message }); | ||
} | ||
}); | ||
@@ -873,3 +880,3 @@ } | ||
evaluate(flagKey, resolver, defaultValue, flagType, options = {}) { | ||
var _a; | ||
var _a, _b; | ||
const allHooks = [ | ||
@@ -882,3 +889,3 @@ ...OpenFeature.getHooks(), | ||
const allHooksReversed = [...allHooks].reverse(); | ||
const context = __spreadValues({}, OpenFeature.getContext()); | ||
const context = __spreadValues({}, OpenFeature.getContext((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.name)); | ||
const hookContext = { | ||
@@ -897,3 +904,3 @@ flagKey, | ||
const evaluationDetails = __spreadProps(__spreadValues({}, resolution), { | ||
flagMetadata: Object.freeze((_a = resolution.flagMetadata) != null ? _a : {}), | ||
flagMetadata: Object.freeze((_b = resolution.flagMetadata) != null ? _b : {}), | ||
flagKey | ||
@@ -900,0 +907,0 @@ }); |
@@ -671,9 +671,15 @@ var __create = Object.create; | ||
this._context = context; | ||
const providersWithoutContextOverride = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [, provider]) => { | ||
acc.push(provider); | ||
const defaultContextNameProviders = Array.from(this._clientProviders.entries()).filter(([name]) => !this._namedProviderContext.has(name)).reduce((acc, [name, provider]) => { | ||
acc.push({ name, provider }); | ||
return acc; | ||
}, []); | ||
const allProviders = [this._defaultProvider, ...providersWithoutContextOverride]; | ||
const allProviders = [ | ||
// add in the default (no name) | ||
{ name: void 0, provider: this._defaultProvider }, | ||
...defaultContextNameProviders | ||
]; | ||
yield Promise.all( | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(void 0, provider, oldContext, context)) | ||
allProviders.map( | ||
(tuple) => this.runProviderContextChangeHandler(tuple.name, tuple.provider, oldContext, context) | ||
) | ||
); | ||
@@ -756,18 +762,19 @@ } | ||
return __async(this, null, function* () { | ||
var _a; | ||
var _a, _b, _c, _d, _e; | ||
const providerName = provider.metadata.name; | ||
return (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext).then(() => { | ||
var _a2; | ||
try { | ||
yield (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}); | ||
(_a2 = this._events) == null ? void 0 : _a2.emit(ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}).catch((err) => { | ||
var _a2, _b; | ||
(_a2 = this._logger) == null ? void 0 : _a2.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
(_b = this._events) == null ? void 0 : _b.emit(ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
} catch (err) { | ||
const error = err; | ||
const message = `Error running ${(_c = provider == null ? void 0 : provider.metadata) == null ? void 0 : _c.name}'s context change handler: ${error == null ? void 0 : error.message}`; | ||
(_d = this._logger) == null ? void 0 : _d.error(`${message}`, err); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
emitter == null ? void 0 : emitter.emit(ClientProviderEvents.Error, { clientName, providerName, message }); | ||
}); | ||
(_b = this._events) == null ? void 0 : _b.emit(ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
(_e = this._events) == null ? void 0 : _e.emit(ClientProviderEvents.Error, { clientName, providerName, message }); | ||
} | ||
}); | ||
@@ -870,3 +877,3 @@ } | ||
evaluate(flagKey, resolver, defaultValue, flagType, options = {}) { | ||
var _a; | ||
var _a, _b; | ||
const allHooks = [ | ||
@@ -879,3 +886,3 @@ ...OpenFeature.getHooks(), | ||
const allHooksReversed = [...allHooks].reverse(); | ||
const context = __spreadValues({}, OpenFeature.getContext()); | ||
const context = __spreadValues({}, OpenFeature.getContext((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.name)); | ||
const hookContext = { | ||
@@ -894,3 +901,3 @@ flagKey, | ||
const evaluationDetails = __spreadProps(__spreadValues({}, resolution), { | ||
flagMetadata: Object.freeze((_a = resolution.flagMetadata) != null ? _a : {}), | ||
flagMetadata: Object.freeze((_b = resolution.flagMetadata) != null ? _b : {}), | ||
flagKey | ||
@@ -897,0 +904,0 @@ }); |
@@ -580,2 +580,6 @@ import EventEmitter from 'events'; | ||
/** | ||
* Removes all event handlers. | ||
*/ | ||
clearHandlers(): void; | ||
/** | ||
* Gets the current handlers for the given provider event type. | ||
@@ -951,3 +955,3 @@ * @param {AnyProviderEvent} eventType The provider event type to get the current handlers for | ||
*/ | ||
getContext(clientName: string): EvaluationContext; | ||
getContext(clientName?: string): EvaluationContext; | ||
/** | ||
@@ -954,0 +958,0 @@ * Resets the global evaluation context to an empty object. |
{ | ||
"name": "@openfeature/web-sdk", | ||
"version": "0.4.9", | ||
"version": "0.4.10", | ||
"description": "OpenFeature SDK for Web", | ||
@@ -49,7 +49,7 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"@openfeature/core": "0.0.22" | ||
"@openfeature/core": "0.0.23" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "0.0.22" | ||
"@openfeature/core": "0.0.23" | ||
} | ||
} |
@@ -19,4 +19,4 @@ <!-- markdownlint-disable MD033 --> | ||
<!-- x-release-please-start-version --> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.9"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.9&color=blue&style=for-the-badge" /> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.10"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.10&color=blue&style=for-the-badge" /> | ||
</a> | ||
@@ -23,0 +23,0 @@ <!-- x-release-please-end --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
268030
2884