@spotify-confidence/openfeature-server-provider
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -12,3 +12,2 @@ import { ProviderMetadata, ProviderStatus, EvaluationContext, Logger, ResolutionDetails, JsonValue, Provider } from '@openfeature/js-sdk'; | ||
private readonly client; | ||
private configuration; | ||
private readonly applyManager; | ||
@@ -15,0 +14,0 @@ constructor(client: ConfidenceClient, options?: ConfidenceServerProviderOptions); |
@@ -22,9 +22,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConfidenceServerProvider = void 0; | ||
const js_sdk_1 = require("@openfeature/js-sdk"); | ||
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); | ||
const client_http_1 = require("@spotify-confidence/client-http"); | ||
@@ -38,3 +34,2 @@ class ConfidenceServerProvider { | ||
this.status = js_sdk_1.ProviderStatus.READY; | ||
this.configuration = null; | ||
this.client = client; | ||
@@ -50,4 +45,4 @@ this.applyManager = new client_http_1.ApplyManager({ client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
} | ||
getFlag(flagKey, defaultValue, _logger) { | ||
if (!this.configuration) { | ||
getFlag(configuration, flagKey, defaultValue, _logger) { | ||
if (!configuration) { | ||
return { | ||
@@ -61,3 +56,3 @@ errorCode: js_sdk_1.ErrorCode.PROVIDER_NOT_READY, | ||
try { | ||
const flag = this.configuration.flags[`flags/${flagName}`]; | ||
const flag = configuration.flags[`flags/${flagName}`]; | ||
if (!flag) { | ||
@@ -98,3 +93,3 @@ return { | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
this.applyManager.apply(configuration.resolveToken, flagName); | ||
return { | ||
@@ -105,3 +100,3 @@ value: flagValue.value, | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken || '', | ||
resolveToken: configuration.resolveToken || '', | ||
}, | ||
@@ -121,11 +116,6 @@ }; | ||
const [flagName, ..._] = flagKey.split('.'); | ||
if (!!this.configuration && (0, fast_deep_equal_1.default)(this.configuration.context, this.convertContext(context))) { | ||
if (this.configuration.flags[`flags/${flagName}`]) { | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
} | ||
} | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
const configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [`flags/${flagName}`], | ||
}); | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
return this.getFlag(configuration, flagKey, defaultValue, logger); | ||
}); | ||
@@ -132,0 +122,0 @@ } |
@@ -12,3 +12,2 @@ import { ProviderMetadata, ProviderStatus, EvaluationContext, Logger, ResolutionDetails, JsonValue, Provider } from '@openfeature/js-sdk'; | ||
private readonly client; | ||
private configuration; | ||
private readonly applyManager; | ||
@@ -15,0 +14,0 @@ constructor(client: ConfidenceClient, options?: ConfidenceServerProviderOptions); |
@@ -22,3 +22,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { ProviderStatus, ErrorCode, } from '@openfeature/js-sdk'; | ||
import equal from 'fast-deep-equal'; | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
@@ -32,3 +31,2 @@ export class ConfidenceServerProvider { | ||
this.status = ProviderStatus.READY; | ||
this.configuration = null; | ||
this.client = client; | ||
@@ -44,4 +42,4 @@ this.applyManager = new ApplyManager({ client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
} | ||
getFlag(flagKey, defaultValue, _logger) { | ||
if (!this.configuration) { | ||
getFlag(configuration, flagKey, defaultValue, _logger) { | ||
if (!configuration) { | ||
return { | ||
@@ -55,3 +53,3 @@ errorCode: ErrorCode.PROVIDER_NOT_READY, | ||
try { | ||
const flag = this.configuration.flags[`flags/${flagName}`]; | ||
const flag = configuration.flags[`flags/${flagName}`]; | ||
if (!flag) { | ||
@@ -92,3 +90,3 @@ return { | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
this.applyManager.apply(configuration.resolveToken, flagName); | ||
return { | ||
@@ -99,3 +97,3 @@ value: flagValue.value, | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken || '', | ||
resolveToken: configuration.resolveToken || '', | ||
}, | ||
@@ -115,11 +113,6 @@ }; | ||
const [flagName, ..._] = flagKey.split('.'); | ||
if (!!this.configuration && equal(this.configuration.context, this.convertContext(context))) { | ||
if (this.configuration.flags[`flags/${flagName}`]) { | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
} | ||
} | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
const configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [`flags/${flagName}`], | ||
}); | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
return this.getFlag(configuration, flagKey, defaultValue, logger); | ||
}); | ||
@@ -126,0 +119,0 @@ } |
@@ -12,3 +12,2 @@ import { ProviderMetadata, ProviderStatus, EvaluationContext, Logger, ResolutionDetails, JsonValue, Provider } from '@openfeature/js-sdk'; | ||
private readonly client; | ||
private configuration; | ||
private readonly applyManager; | ||
@@ -15,0 +14,0 @@ constructor(client: ConfidenceClient, options?: ConfidenceServerProviderOptions); |
@@ -22,3 +22,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { ProviderStatus, ErrorCode, } from '@openfeature/js-sdk'; | ||
import equal from 'fast-deep-equal'; | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
@@ -32,3 +31,2 @@ export class ConfidenceServerProvider { | ||
this.status = ProviderStatus.READY; | ||
this.configuration = null; | ||
this.client = client; | ||
@@ -44,4 +42,4 @@ this.applyManager = new ApplyManager({ client, timeout: ((_a = options === null || options === void 0 ? void 0 : options.apply) === null || _a === void 0 ? void 0 : _a.timeout) || 250 }); | ||
} | ||
getFlag(flagKey, defaultValue, _logger) { | ||
if (!this.configuration) { | ||
getFlag(configuration, flagKey, defaultValue, _logger) { | ||
if (!configuration) { | ||
return { | ||
@@ -55,3 +53,3 @@ errorCode: ErrorCode.PROVIDER_NOT_READY, | ||
try { | ||
const flag = this.configuration.flags[`flags/${flagName}`]; | ||
const flag = configuration.flags[`flags/${flagName}`]; | ||
if (!flag) { | ||
@@ -92,3 +90,3 @@ return { | ||
} | ||
this.applyManager.apply(this.configuration.resolveToken, flagName); | ||
this.applyManager.apply(configuration.resolveToken, flagName); | ||
return { | ||
@@ -99,3 +97,3 @@ value: flagValue.value, | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken || '', | ||
resolveToken: configuration.resolveToken || '', | ||
}, | ||
@@ -115,11 +113,6 @@ }; | ||
const [flagName, ..._] = flagKey.split('.'); | ||
if (!!this.configuration && equal(this.configuration.context, this.convertContext(context))) { | ||
if (this.configuration.flags[`flags/${flagName}`]) { | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
} | ||
} | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
const configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [`flags/${flagName}`], | ||
}); | ||
return this.getFlag(flagKey, defaultValue, logger); | ||
return this.getFlag(configuration, flagKey, defaultValue, logger); | ||
}); | ||
@@ -126,0 +119,0 @@ } |
@@ -1,3 +0,22 @@ | ||
# Change Log | ||
# Changelog | ||
## [0.0.4](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-server-provider-v0.0.3...openfeature-server-provider-v0.0.4) (2023-10-18) | ||
### 🐛 Bug Fixes | ||
* **server:** do not cache request ([#26](https://github.com/spotify/confidence-openfeature-provider-js/issues/26)) ([8205694](https://github.com/spotify/confidence-openfeature-provider-js/commit/82056948938a0d47418cb437bc1319ddd5ff10f7)) | ||
### ✨ New Features | ||
* **examples:** add node js commonjs example ([9e9b2ad](https://github.com/spotify/confidence-openfeature-provider-js/commit/9e9b2add53ac26276d890d77f113c2e61d953ff6)) | ||
### 📚 Documentation | ||
* **server:** update docs with correct example ([ff794fa](https://github.com/spotify/confidence-openfeature-provider-js/commit/ff794fadf2eb942622e4b0eaf9666b5db0059625)) | ||
## Change Log (Old) | ||
All notable changes to this project will be documented in this file. | ||
@@ -4,0 +23,0 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
{ | ||
"name": "@spotify-confidence/openfeature-server-provider", | ||
"license": "Apache-2.0", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"module": "build/esm/index.js", | ||
@@ -9,4 +9,3 @@ "main": "build/cjs/index.js", | ||
"dependencies": { | ||
"@spotify-confidence/client-http": "^0.0.2", | ||
"fast-deep-equal": "^3.1.3" | ||
"@spotify-confidence/client-http": "^0.0.2" | ||
}, | ||
@@ -25,3 +24,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "c377e3d6611011820bd7799860f96aa1f5fcbe0b" | ||
"gitHead": "0353749d82a14bb8db34aef3a9055097c202b898" | ||
} |
@@ -22,7 +22,6 @@ # OpenFeature JS SDK JavaScript Confidence Provider | ||
import { createConfidenceServerProvider } from '@spotify-confidence/openfeature-server-provider'; | ||
import { OpenFeature, OpenFeatureAPI } from '@openfeature/js-sdk'; | ||
import { fetch } from 'node-fetch'; | ||
import { OpenFeature } from '@openfeature/js-sdk'; | ||
const provider = createConfidenceServerProvider({ | ||
clientSecret: 'mysecret', | ||
clientSecret: 'your-client-secret', | ||
region: 'eu', | ||
@@ -33,8 +32,12 @@ fetchImplementation: fetch, | ||
OpenFeature.setProvider(provider); | ||
OpenFeature.setContext({ targetingKey: 'myTargetingKey' }); | ||
const client = OpenFeature.getClient(); | ||
const result = await client.getBooleanValue('flag.my-boolean', false, { | ||
someOtherContext: true, | ||
}); | ||
client | ||
.getBooleanValue('flagname.bool', false, { | ||
targetingKey: `your targeting key`, | ||
}) | ||
.then(result => { | ||
console.log('result:', result); | ||
}); | ||
``` |
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
166218
2
42
550
- Removedfast-deep-equal@^3.1.3
- Removedfast-deep-equal@3.1.3(transitive)