@spotify-confidence/openfeature-web-provider
Advanced tools
Comparing version 0.0.4 to 0.1.0
import { EvaluationContext, JsonValue, Logger, OpenFeatureEventEmitter, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/web-sdk'; | ||
import { ConfidenceClient, Configuration } from '@spotify-confidence/client-http'; | ||
export interface ConfidenceWebProviderOptions { | ||
apply?: { | ||
timeout?: number; | ||
}; | ||
apply: 'access' | 'backend'; | ||
} | ||
@@ -15,3 +13,3 @@ export declare class ConfidenceWebProvider implements Provider { | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options?: ConfidenceWebProviderOptions); | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -18,0 +16,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -30,5 +30,5 @@ "use strict"; | ||
const client_http_1 = require("@spotify-confidence/client-http"); | ||
const APPLY_TIMEOUT = 250; | ||
class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
var _a; | ||
this.metadata = { | ||
@@ -40,4 +40,7 @@ name: 'ConfidenceWebProvider', | ||
this.events = new web_sdk_1.OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
this.applyManager = new client_http_1.ApplyManager({ client: this.client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new client_http_1.ApplyManager({ client: this.client, timeout: APPLY_TIMEOUT }); | ||
} | ||
} | ||
@@ -87,2 +90,3 @@ initialize(context) { | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a; | ||
if (!this.configuration) { | ||
@@ -139,3 +143,3 @@ logger.warn('Provider not ready'); | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -142,0 +146,0 @@ return { |
@@ -7,5 +7,4 @@ import { Provider } from '@openfeature/web-sdk'; | ||
baseUrl?: string; | ||
apply?: { | ||
timeout: number; | ||
}; | ||
apply?: 'access' | 'backend'; | ||
timeout: number; | ||
}; | ||
@@ -12,0 +11,0 @@ export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; |
@@ -7,5 +7,5 @@ "use strict"; | ||
function createConfidenceWebProvider(options) { | ||
const confidenceClient = new client_http_1.ConfidenceClient(Object.assign(Object.assign({}, options), { apply: !options.apply })); | ||
const confidenceClient = new client_http_1.ConfidenceClient(Object.assign(Object.assign({}, options), { apply: options.apply === 'backend' })); | ||
return new ConfidenceWebProvider_1.ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply, | ||
apply: options.apply || 'access', | ||
}); | ||
@@ -12,0 +12,0 @@ } |
import { EvaluationContext, JsonValue, Logger, OpenFeatureEventEmitter, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/web-sdk'; | ||
import { ConfidenceClient, Configuration } from '@spotify-confidence/client-http'; | ||
export interface ConfidenceWebProviderOptions { | ||
apply?: { | ||
timeout?: number; | ||
}; | ||
apply: 'access' | 'backend'; | ||
} | ||
@@ -15,3 +13,3 @@ export declare class ConfidenceWebProvider implements Provider { | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options?: ConfidenceWebProviderOptions); | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -18,0 +16,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -24,5 +24,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
const APPLY_TIMEOUT = 250; | ||
export class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
var _a; | ||
this.metadata = { | ||
@@ -34,4 +34,7 @@ name: 'ConfidenceWebProvider', | ||
this.events = new OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
this.applyManager = new ApplyManager({ client: this.client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new ApplyManager({ client: this.client, timeout: APPLY_TIMEOUT }); | ||
} | ||
} | ||
@@ -81,2 +84,3 @@ initialize(context) { | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a; | ||
if (!this.configuration) { | ||
@@ -133,3 +137,3 @@ logger.warn('Provider not ready'); | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -136,0 +140,0 @@ return { |
@@ -7,5 +7,4 @@ import { Provider } from '@openfeature/web-sdk'; | ||
baseUrl?: string; | ||
apply?: { | ||
timeout: number; | ||
}; | ||
apply?: 'access' | 'backend'; | ||
timeout: number; | ||
}; | ||
@@ -12,0 +11,0 @@ export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; |
import { ConfidenceWebProvider } from './ConfidenceWebProvider'; | ||
import { ConfidenceClient } from '@spotify-confidence/client-http'; | ||
export function createConfidenceWebProvider(options) { | ||
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: !options.apply })); | ||
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: options.apply === 'backend' })); | ||
return new ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply, | ||
apply: options.apply || 'access', | ||
}); | ||
} | ||
//# sourceMappingURL=factory.js.map |
import { EvaluationContext, JsonValue, Logger, OpenFeatureEventEmitter, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/web-sdk'; | ||
import { ConfidenceClient, Configuration } from '@spotify-confidence/client-http'; | ||
export interface ConfidenceWebProviderOptions { | ||
apply?: { | ||
timeout?: number; | ||
}; | ||
apply: 'access' | 'backend'; | ||
} | ||
@@ -15,3 +13,3 @@ export declare class ConfidenceWebProvider implements Provider { | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options?: ConfidenceWebProviderOptions); | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -18,0 +16,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -24,5 +24,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
const APPLY_TIMEOUT = 250; | ||
export class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
var _a; | ||
this.metadata = { | ||
@@ -34,4 +34,7 @@ name: 'ConfidenceWebProvider', | ||
this.events = new OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
this.applyManager = new ApplyManager({ client: this.client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new ApplyManager({ client: this.client, timeout: APPLY_TIMEOUT }); | ||
} | ||
} | ||
@@ -81,2 +84,3 @@ initialize(context) { | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a; | ||
if (!this.configuration) { | ||
@@ -133,3 +137,3 @@ logger.warn('Provider not ready'); | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -136,0 +140,0 @@ return { |
@@ -7,5 +7,4 @@ import { Provider } from '@openfeature/web-sdk'; | ||
baseUrl?: string; | ||
apply?: { | ||
timeout: number; | ||
}; | ||
apply?: 'access' | 'backend'; | ||
timeout: number; | ||
}; | ||
@@ -12,0 +11,0 @@ export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; |
import { ConfidenceWebProvider } from './ConfidenceWebProvider'; | ||
import { ConfidenceClient } from '@spotify-confidence/client-http'; | ||
export function createConfidenceWebProvider(options) { | ||
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: !options.apply })); | ||
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: options.apply === 'backend' })); | ||
return new ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply, | ||
apply: options.apply || 'access', | ||
}); | ||
} | ||
//# sourceMappingURL=factory.js.map |
# Changelog | ||
## [0.1.0](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-web-provider-v0.0.4...openfeature-web-provider-v0.1.0) (2023-11-15) | ||
### ⚠ BREAKING CHANGES | ||
* **client-http,web,server,react,examples:** new required option: timeout | ||
### ✨ New Features | ||
* **client-http,web,server,react,examples:** add timeout for network request ([f460b97](https://github.com/spotify/confidence-openfeature-provider-js/commit/f460b97ec4e1c56375de52fd1eb664c7b9be1f35)) | ||
### 📚 Documentation | ||
* add concept apply docs ([0274284](https://github.com/spotify/confidence-openfeature-provider-js/commit/02742845d029e994c0f83c4acc2bff9f796a3dad)) | ||
### 🔄 Refactoring | ||
* **web:** set access apply to default, add docs ([91d9ebf](https://github.com/spotify/confidence-openfeature-provider-js/commit/91d9ebff2ee826d6549587406e0ab61584ce0263)) | ||
## [0.0.4](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-web-provider-v0.0.3...openfeature-web-provider-v0.0.4) (2023-10-26) | ||
@@ -4,0 +25,0 @@ |
{ | ||
"name": "@spotify-confidence/openfeature-web-provider", | ||
"license": "Apache-2.0", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"module": "build/esm/index.js", | ||
@@ -24,3 +24,3 @@ "main": "build/cjs/index.js", | ||
}, | ||
"gitHead": "6066377a115fb694a7af12ee1a7dc60f73b2fee3" | ||
"gitHead": "2bf37b7bab49dfe95fe753ad28689827d9885743" | ||
} |
@@ -34,2 +34,3 @@ # OpenFeature Web SDK JavaScript Confidence Provider | ||
fetchImplementation: window.fetch.bind(window), | ||
timeout: 1000, | ||
}); | ||
@@ -50,1 +51,21 @@ | ||
- It's advised not to perform resolves while `setProvider` and `setContext` are running: resolves might return the default value with reason `STALE` during such operations. | ||
## Timeout | ||
The timeout option is used to set the timeout for the network request to the Confidence backend. When the timeout is reached, default values will be returned. | ||
## Configuring Apply | ||
See [apply concept](../../concepts/apply.md). | ||
By default, `'access'` apply is used, using a timeout of 250ms. | ||
To use Backend Apply, set the apply option to `'backend'`: | ||
```ts | ||
const provider = createConfidenceWebProvider({ | ||
..., | ||
apply: 'backend' | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
180306
709
70