@spotify-confidence/openfeature-web-provider
Advanced tools
Comparing version 0.1.5 to 0.2.0-rc.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: 'access' | 'backend'; | ||
} | ||
import { Confidence, FlagResolution } from '@spotify-confidence/sdk'; | ||
export declare class ConfidenceWebProvider implements Provider { | ||
readonly metadata: ProviderMetadata; | ||
status: ProviderStatus; | ||
configuration: Configuration | null; | ||
flagResolution: FlagResolution | null; | ||
readonly events: OpenFeatureEventEmitter; | ||
private readonly client; | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
private readonly confidence; | ||
constructor(confidence: Confidence); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -15,0 +11,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -29,7 +29,5 @@ "use strict"; | ||
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); | ||
const client_http_1 = require("@spotify-confidence/client-http"); | ||
const APPLY_TIMEOUT = 250; | ||
const MAX_APPLY_BUFFER_SIZE = 20; | ||
const sdk_1 = require("@spotify-confidence/sdk"); | ||
class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
constructor(confidence) { | ||
this.metadata = { | ||
@@ -39,13 +37,5 @@ name: 'ConfidenceWebProvider', | ||
this.status = web_sdk_1.ProviderStatus.NOT_READY; | ||
this.configuration = null; | ||
this.flagResolution = null; | ||
this.events = new web_sdk_1.OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new client_http_1.ApplyManager({ | ||
client: this.client, | ||
timeout: APPLY_TIMEOUT, | ||
maxBufferSize: MAX_APPLY_BUFFER_SIZE, | ||
}); | ||
} | ||
this.confidence = confidence; | ||
} | ||
@@ -55,5 +45,5 @@ initialize(context) { | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [], | ||
}); | ||
if (context) | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(context || {})); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = web_sdk_1.ProviderStatus.READY; | ||
@@ -75,6 +65,4 @@ return Promise.resolve(); | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(newContext || {}), { | ||
apply: false, | ||
flags: [], | ||
}); | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(newContext)); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = web_sdk_1.ProviderStatus.READY; | ||
@@ -89,12 +77,26 @@ this.events.emit(web_sdk_1.ProviderEvents.Ready); | ||
} | ||
convertContext(context) { | ||
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]); | ||
if (targetingKey) { | ||
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey }); | ||
convertContext(_a) { | ||
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]); | ||
return Object.assign({ targeting_key: targetingKey }, convert(rest)); | ||
function convert(value) { | ||
if (value === null) | ||
return undefined; | ||
if (typeof value === 'object') { | ||
if (Array.isArray(value)) { | ||
return value.map(convert); | ||
} | ||
if (value instanceof Date) { | ||
return value.toISOString(); | ||
} | ||
const struct = {}; | ||
for (const key of Object.keys(value)) { | ||
struct[key] = convert(value[key]); | ||
} | ||
return struct; | ||
} | ||
return value; | ||
} | ||
return rest; | ||
} | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a, _b; | ||
if (!this.configuration) { | ||
if (!this.flagResolution) { | ||
logger.warn('Provider not ready'); | ||
@@ -107,3 +109,3 @@ return { | ||
} | ||
if (!(0, fast_deep_equal_1.default)(this.configuration.context, this.convertContext(context))) { | ||
if (!(0, fast_deep_equal_1.default)(this.flagResolution.context, this.convertContext(context))) { | ||
return { | ||
@@ -116,3 +118,3 @@ value: defaultValue, | ||
try { | ||
const flag = this.configuration.flags[flagName]; | ||
const flag = this.flagResolution.flags[flagName]; | ||
if (!flag) { | ||
@@ -126,4 +128,6 @@ logger.warn('Flag "%s" was not found', flagName); | ||
} | ||
if (client_http_1.Configuration.ResolveReason.NoSegmentMatch === flag.reason) { | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
if (sdk_1.FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) { | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
return { | ||
@@ -136,3 +140,3 @@ value: defaultValue, | ||
try { | ||
flagValue = client_http_1.Configuration.FlagValue.traverse(flag, pathParts.join('.')); | ||
flagValue = sdk_1.FlagResolution.FlagValue.traverse(flag, pathParts.join('.')); | ||
} | ||
@@ -153,3 +157,3 @@ catch (e) { | ||
} | ||
if (!client_http_1.Configuration.FlagValue.matches(flagValue, defaultValue)) { | ||
if (!sdk_1.FlagResolution.FlagValue.matches(flagValue, defaultValue)) { | ||
logger.warn('Value for "%s" is of incorrect type', flagKey); | ||
@@ -162,3 +166,5 @@ return { | ||
} | ||
(_b = this.applyManager) === null || _b === void 0 ? void 0 : _b.apply(this.configuration.resolveToken, flagName); | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -170,3 +176,3 @@ return { | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken, | ||
resolveToken: this.flagResolution.resolveToken, | ||
}, | ||
@@ -200,7 +206,7 @@ }; | ||
switch (reason) { | ||
case client_http_1.Configuration.ResolveReason.Archived: | ||
case sdk_1.FlagResolution.ResolveReason.Archived: | ||
return 'DISABLED'; | ||
case client_http_1.Configuration.ResolveReason.Unspecified: | ||
case sdk_1.FlagResolution.ResolveReason.Unspecified: | ||
return 'UNKNOWN'; | ||
case client_http_1.Configuration.ResolveReason.Match: | ||
case sdk_1.FlagResolution.ResolveReason.Match: | ||
return 'TARGETING_MATCH'; | ||
@@ -207,0 +213,0 @@ default: |
import { Provider } from '@openfeature/web-sdk'; | ||
import { ConfidenceClientOptions } from '@spotify-confidence/client-http'; | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
type ConfidenceWebProviderFactoryOptions = { | ||
region?: ConfidenceClientOptions['region']; | ||
fetchImplementation: typeof fetch; | ||
region?: 'global' | 'eu' | 'us'; | ||
fetchImplementation?: typeof fetch; | ||
clientSecret: string; | ||
@@ -12,3 +12,4 @@ baseUrl?: string; | ||
export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; | ||
export declare function createConfidenceWebProvider(confidence: Confidence): Provider; | ||
export {}; | ||
//# sourceMappingURL=factory.d.ts.map |
@@ -5,13 +5,11 @@ "use strict"; | ||
const ConfidenceWebProvider_1 = require("./ConfidenceWebProvider"); | ||
const client_http_1 = require("@spotify-confidence/client-http"); | ||
function createConfidenceWebProvider(options) { | ||
const confidenceClient = new client_http_1.ConfidenceClient(Object.assign(Object.assign({}, options), { apply: options.apply === 'backend', sdk: { | ||
id: 'SDK_ID_JS_WEB_PROVIDER', | ||
version: '0.1.5', | ||
} })); | ||
return new ConfidenceWebProvider_1.ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply || 'access', | ||
}); | ||
const sdk_1 = require("@spotify-confidence/sdk"); | ||
function createConfidenceWebProvider(confidenceOrOptions) { | ||
if (confidenceOrOptions instanceof sdk_1.Confidence) { | ||
return new ConfidenceWebProvider_1.ConfidenceWebProvider(confidenceOrOptions); | ||
} | ||
const confidence = sdk_1.Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'client' })); | ||
return new ConfidenceWebProvider_1.ConfidenceWebProvider(confidence); | ||
} | ||
exports.createConfidenceWebProvider = createConfidenceWebProvider; | ||
//# sourceMappingURL=factory.js.map |
export type * from './ConfidenceWebProvider'; | ||
export * from './factory'; | ||
export { createConfidenceWebProvider } from './factory'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./factory"), exports); | ||
exports.createConfidenceWebProvider = void 0; | ||
var factory_1 = require("./factory"); | ||
Object.defineProperty(exports, "createConfidenceWebProvider", { enumerable: true, get: function () { return factory_1.createConfidenceWebProvider; } }); | ||
//# sourceMappingURL=index.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: 'access' | 'backend'; | ||
} | ||
import { Confidence, FlagResolution } from '@spotify-confidence/sdk'; | ||
export declare class ConfidenceWebProvider implements Provider { | ||
readonly metadata: ProviderMetadata; | ||
status: ProviderStatus; | ||
configuration: Configuration | null; | ||
flagResolution: FlagResolution | null; | ||
readonly events: OpenFeatureEventEmitter; | ||
private readonly client; | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
private readonly confidence; | ||
constructor(confidence: Confidence); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -15,0 +11,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -23,7 +23,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import equal from 'fast-deep-equal'; | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
const APPLY_TIMEOUT = 250; | ||
const MAX_APPLY_BUFFER_SIZE = 20; | ||
import { FlagResolution } from '@spotify-confidence/sdk'; | ||
export class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
constructor(confidence) { | ||
this.metadata = { | ||
@@ -33,13 +31,5 @@ name: 'ConfidenceWebProvider', | ||
this.status = ProviderStatus.NOT_READY; | ||
this.configuration = null; | ||
this.flagResolution = null; | ||
this.events = new OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new ApplyManager({ | ||
client: this.client, | ||
timeout: APPLY_TIMEOUT, | ||
maxBufferSize: MAX_APPLY_BUFFER_SIZE, | ||
}); | ||
} | ||
this.confidence = confidence; | ||
} | ||
@@ -49,5 +39,5 @@ initialize(context) { | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [], | ||
}); | ||
if (context) | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(context || {})); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = ProviderStatus.READY; | ||
@@ -69,6 +59,4 @@ return Promise.resolve(); | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(newContext || {}), { | ||
apply: false, | ||
flags: [], | ||
}); | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(newContext)); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = ProviderStatus.READY; | ||
@@ -83,12 +71,26 @@ this.events.emit(ProviderEvents.Ready); | ||
} | ||
convertContext(context) { | ||
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]); | ||
if (targetingKey) { | ||
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey }); | ||
convertContext(_a) { | ||
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]); | ||
return Object.assign({ targeting_key: targetingKey }, convert(rest)); | ||
function convert(value) { | ||
if (value === null) | ||
return undefined; | ||
if (typeof value === 'object') { | ||
if (Array.isArray(value)) { | ||
return value.map(convert); | ||
} | ||
if (value instanceof Date) { | ||
return value.toISOString(); | ||
} | ||
const struct = {}; | ||
for (const key of Object.keys(value)) { | ||
struct[key] = convert(value[key]); | ||
} | ||
return struct; | ||
} | ||
return value; | ||
} | ||
return rest; | ||
} | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a, _b; | ||
if (!this.configuration) { | ||
if (!this.flagResolution) { | ||
logger.warn('Provider not ready'); | ||
@@ -101,3 +103,3 @@ return { | ||
} | ||
if (!equal(this.configuration.context, this.convertContext(context))) { | ||
if (!equal(this.flagResolution.context, this.convertContext(context))) { | ||
return { | ||
@@ -110,3 +112,3 @@ value: defaultValue, | ||
try { | ||
const flag = this.configuration.flags[flagName]; | ||
const flag = this.flagResolution.flags[flagName]; | ||
if (!flag) { | ||
@@ -120,4 +122,6 @@ logger.warn('Flag "%s" was not found', flagName); | ||
} | ||
if (Configuration.ResolveReason.NoSegmentMatch === flag.reason) { | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
if (FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) { | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
return { | ||
@@ -130,3 +134,3 @@ value: defaultValue, | ||
try { | ||
flagValue = Configuration.FlagValue.traverse(flag, pathParts.join('.')); | ||
flagValue = FlagResolution.FlagValue.traverse(flag, pathParts.join('.')); | ||
} | ||
@@ -147,3 +151,3 @@ catch (e) { | ||
} | ||
if (!Configuration.FlagValue.matches(flagValue, defaultValue)) { | ||
if (!FlagResolution.FlagValue.matches(flagValue, defaultValue)) { | ||
logger.warn('Value for "%s" is of incorrect type', flagKey); | ||
@@ -156,3 +160,5 @@ return { | ||
} | ||
(_b = this.applyManager) === null || _b === void 0 ? void 0 : _b.apply(this.configuration.resolveToken, flagName); | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -164,3 +170,3 @@ return { | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken, | ||
resolveToken: this.flagResolution.resolveToken, | ||
}, | ||
@@ -193,7 +199,7 @@ }; | ||
switch (reason) { | ||
case Configuration.ResolveReason.Archived: | ||
case FlagResolution.ResolveReason.Archived: | ||
return 'DISABLED'; | ||
case Configuration.ResolveReason.Unspecified: | ||
case FlagResolution.ResolveReason.Unspecified: | ||
return 'UNKNOWN'; | ||
case Configuration.ResolveReason.Match: | ||
case FlagResolution.ResolveReason.Match: | ||
return 'TARGETING_MATCH'; | ||
@@ -200,0 +206,0 @@ default: |
import { Provider } from '@openfeature/web-sdk'; | ||
import { ConfidenceClientOptions } from '@spotify-confidence/client-http'; | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
type ConfidenceWebProviderFactoryOptions = { | ||
region?: ConfidenceClientOptions['region']; | ||
fetchImplementation: typeof fetch; | ||
region?: 'global' | 'eu' | 'us'; | ||
fetchImplementation?: typeof fetch; | ||
clientSecret: string; | ||
@@ -12,3 +12,4 @@ baseUrl?: string; | ||
export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; | ||
export declare function createConfidenceWebProvider(confidence: Confidence): Provider; | ||
export {}; | ||
//# sourceMappingURL=factory.d.ts.map |
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 === 'backend', sdk: { | ||
id: 'SDK_ID_JS_WEB_PROVIDER', | ||
version: '0.1.5', | ||
} })); | ||
return new ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply || 'access', | ||
}); | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
export function createConfidenceWebProvider(confidenceOrOptions) { | ||
if (confidenceOrOptions instanceof Confidence) { | ||
return new ConfidenceWebProvider(confidenceOrOptions); | ||
} | ||
const confidence = Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'client' })); | ||
return new ConfidenceWebProvider(confidence); | ||
} | ||
//# sourceMappingURL=factory.js.map |
export type * from './ConfidenceWebProvider'; | ||
export * from './factory'; | ||
export { createConfidenceWebProvider } from './factory'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export * from './factory'; | ||
export { createConfidenceWebProvider } from './factory'; | ||
//# sourceMappingURL=index.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: 'access' | 'backend'; | ||
} | ||
import { Confidence, FlagResolution } from '@spotify-confidence/sdk'; | ||
export declare class ConfidenceWebProvider implements Provider { | ||
readonly metadata: ProviderMetadata; | ||
status: ProviderStatus; | ||
configuration: Configuration | null; | ||
flagResolution: FlagResolution | null; | ||
readonly events: OpenFeatureEventEmitter; | ||
private readonly client; | ||
private readonly applyManager; | ||
constructor(client: ConfidenceClient, options: ConfidenceWebProviderOptions); | ||
private readonly confidence; | ||
constructor(confidence: Confidence); | ||
initialize(context?: EvaluationContext): Promise<void>; | ||
@@ -15,0 +11,0 @@ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; |
@@ -23,7 +23,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import equal from 'fast-deep-equal'; | ||
import { ApplyManager, Configuration } from '@spotify-confidence/client-http'; | ||
const APPLY_TIMEOUT = 250; | ||
const MAX_APPLY_BUFFER_SIZE = 20; | ||
import { FlagResolution } from '@spotify-confidence/sdk'; | ||
export class ConfidenceWebProvider { | ||
constructor(client, options) { | ||
constructor(confidence) { | ||
this.metadata = { | ||
@@ -33,13 +31,5 @@ name: 'ConfidenceWebProvider', | ||
this.status = ProviderStatus.NOT_READY; | ||
this.configuration = null; | ||
this.flagResolution = null; | ||
this.events = new OpenFeatureEventEmitter(); | ||
this.applyManager = undefined; | ||
this.client = client; | ||
if (options.apply !== 'backend') { | ||
this.applyManager = new ApplyManager({ | ||
client: this.client, | ||
timeout: APPLY_TIMEOUT, | ||
maxBufferSize: MAX_APPLY_BUFFER_SIZE, | ||
}); | ||
} | ||
this.confidence = confidence; | ||
} | ||
@@ -49,5 +39,5 @@ initialize(context) { | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(context || {}), { | ||
flags: [], | ||
}); | ||
if (context) | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(context || {})); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = ProviderStatus.READY; | ||
@@ -69,6 +59,4 @@ return Promise.resolve(); | ||
try { | ||
this.configuration = yield this.client.resolve(this.convertContext(newContext || {}), { | ||
apply: false, | ||
flags: [], | ||
}); | ||
this.confidence.updateContextEntry('openFeature', this.convertContext(newContext)); | ||
this.flagResolution = yield this.confidence.resolve([]); | ||
this.status = ProviderStatus.READY; | ||
@@ -83,12 +71,26 @@ this.events.emit(ProviderEvents.Ready); | ||
} | ||
convertContext(context) { | ||
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]); | ||
if (targetingKey) { | ||
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey }); | ||
convertContext(_a) { | ||
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]); | ||
return Object.assign({ targeting_key: targetingKey }, convert(rest)); | ||
function convert(value) { | ||
if (value === null) | ||
return undefined; | ||
if (typeof value === 'object') { | ||
if (Array.isArray(value)) { | ||
return value.map(convert); | ||
} | ||
if (value instanceof Date) { | ||
return value.toISOString(); | ||
} | ||
const struct = {}; | ||
for (const key of Object.keys(value)) { | ||
struct[key] = convert(value[key]); | ||
} | ||
return struct; | ||
} | ||
return value; | ||
} | ||
return rest; | ||
} | ||
getFlag(flagKey, defaultValue, context, logger) { | ||
var _a, _b; | ||
if (!this.configuration) { | ||
if (!this.flagResolution) { | ||
logger.warn('Provider not ready'); | ||
@@ -101,3 +103,3 @@ return { | ||
} | ||
if (!equal(this.configuration.context, this.convertContext(context))) { | ||
if (!equal(this.flagResolution.context, this.convertContext(context))) { | ||
return { | ||
@@ -110,3 +112,3 @@ value: defaultValue, | ||
try { | ||
const flag = this.configuration.flags[flagName]; | ||
const flag = this.flagResolution.flags[flagName]; | ||
if (!flag) { | ||
@@ -120,4 +122,6 @@ logger.warn('Flag "%s" was not found', flagName); | ||
} | ||
if (Configuration.ResolveReason.NoSegmentMatch === flag.reason) { | ||
(_a = this.applyManager) === null || _a === void 0 ? void 0 : _a.apply(this.configuration.resolveToken, flagName); | ||
if (FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) { | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
return { | ||
@@ -130,3 +134,3 @@ value: defaultValue, | ||
try { | ||
flagValue = Configuration.FlagValue.traverse(flag, pathParts.join('.')); | ||
flagValue = FlagResolution.FlagValue.traverse(flag, pathParts.join('.')); | ||
} | ||
@@ -147,3 +151,3 @@ catch (e) { | ||
} | ||
if (!Configuration.FlagValue.matches(flagValue, defaultValue)) { | ||
if (!FlagResolution.FlagValue.matches(flagValue, defaultValue)) { | ||
logger.warn('Value for "%s" is of incorrect type', flagKey); | ||
@@ -156,3 +160,5 @@ return { | ||
} | ||
(_b = this.applyManager) === null || _b === void 0 ? void 0 : _b.apply(this.configuration.resolveToken, flagName); | ||
if (this.confidence.environment === 'client') { | ||
this.confidence.apply(this.flagResolution.resolveToken, flagName); | ||
} | ||
logger.info('Value for "%s" successfully evaluated', flagKey); | ||
@@ -164,3 +170,3 @@ return { | ||
flagMetadata: { | ||
resolveToken: this.configuration.resolveToken, | ||
resolveToken: this.flagResolution.resolveToken, | ||
}, | ||
@@ -193,7 +199,7 @@ }; | ||
switch (reason) { | ||
case Configuration.ResolveReason.Archived: | ||
case FlagResolution.ResolveReason.Archived: | ||
return 'DISABLED'; | ||
case Configuration.ResolveReason.Unspecified: | ||
case FlagResolution.ResolveReason.Unspecified: | ||
return 'UNKNOWN'; | ||
case Configuration.ResolveReason.Match: | ||
case FlagResolution.ResolveReason.Match: | ||
return 'TARGETING_MATCH'; | ||
@@ -200,0 +206,0 @@ default: |
import { Provider } from '@openfeature/web-sdk'; | ||
import { ConfidenceClientOptions } from '@spotify-confidence/client-http'; | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
type ConfidenceWebProviderFactoryOptions = { | ||
region?: ConfidenceClientOptions['region']; | ||
fetchImplementation: typeof fetch; | ||
region?: 'global' | 'eu' | 'us'; | ||
fetchImplementation?: typeof fetch; | ||
clientSecret: string; | ||
@@ -12,3 +12,4 @@ baseUrl?: string; | ||
export declare function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider; | ||
export declare function createConfidenceWebProvider(confidence: Confidence): Provider; | ||
export {}; | ||
//# sourceMappingURL=factory.d.ts.map |
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 === 'backend', sdk: { | ||
id: 'SDK_ID_JS_WEB_PROVIDER', | ||
version: '0.1.5', | ||
} })); | ||
return new ConfidenceWebProvider(confidenceClient, { | ||
apply: options.apply || 'access', | ||
}); | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
export function createConfidenceWebProvider(confidenceOrOptions) { | ||
if (confidenceOrOptions instanceof Confidence) { | ||
return new ConfidenceWebProvider(confidenceOrOptions); | ||
} | ||
const confidence = Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'client' })); | ||
return new ConfidenceWebProvider(confidence); | ||
} | ||
//# sourceMappingURL=factory.js.map |
export type * from './ConfidenceWebProvider'; | ||
export * from './factory'; | ||
export { createConfidenceWebProvider } from './factory'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export * from './factory'; | ||
export { createConfidenceWebProvider } from './factory'; | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,37 @@ # Changelog | ||
## [0.2.0-rc.0](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-web-provider-v0.1.5...openfeature-web-provider-v0.2.0-rc.0) (2024-04-04) | ||
### โ BREAKING CHANGES | ||
* Since our peer dependency to `@openfeature/js-sdk` changed into `@openfeature/server-sdk`, users need to install the new package which is concidered a breaking change. | ||
### โจ New Features | ||
* **client-http:** improved request logic ([81aee93](https://github.com/spotify/confidence-openfeature-provider-js/commit/81aee937921d28851400d63284c0ab3a7a882ed1)) | ||
* make provider fetchImplementation optional ([cd242a6](https://github.com/spotify/confidence-openfeature-provider-js/commit/cd242a60804d5565f69d12ec0d35acf8d980f11e)) | ||
* send sdk info with apply events ([6b95d0e](https://github.com/spotify/confidence-openfeature-provider-js/commit/6b95d0ea90059cae6fd71882a13a65ee84eb0e2c)) | ||
### ๐งน Chore | ||
* upgrade OpenFeature dependencies ([8f27a92](https://github.com/spotify/confidence-openfeature-provider-js/commit/8f27a924aa5eb7662fdf73be6564eb2e3580b2fc)) | ||
### ๐ Documentation | ||
* update readme with setProviderAndWait ([6dd6847](https://github.com/spotify/confidence-openfeature-provider-js/commit/6dd6847ce513f31491ed88f75cd13d7f598bc366)) | ||
### ๐ Refactoring | ||
* providers depend on total confidence ([ac4a56b](https://github.com/spotify/confidence-openfeature-provider-js/commit/ac4a56be0e858cdccacd7fef248ebfec3a2e5dc0)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* dependencies | ||
* @spotify-confidence/sdk bumped from 0.0.1 to 0.0.2 | ||
## [0.1.5](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-web-provider-v0.1.4...openfeature-web-provider-v0.1.5) (2024-02-01) | ||
@@ -11,0 +46,0 @@ |
{ | ||
"name": "@spotify-confidence/openfeature-web-provider", | ||
"license": "Apache-2.0", | ||
"version": "0.1.5", | ||
"version": "0.2.0-rc.0", | ||
"module": "build/esm/index.js", | ||
@@ -9,7 +9,11 @@ "main": "build/cjs/index.js", | ||
"dependencies": { | ||
"@spotify-confidence/client-http": "^0.1.4", | ||
"@spotify-confidence/sdk": "0.0.2", | ||
"fast-deep-equal": "^3.1.3" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "^0.0.24", | ||
"@openfeature/web-sdk": "^0.4.11" | ||
}, | ||
"peerDependencies": { | ||
"@openfeature/web-sdk": "^0.4.0" | ||
"@openfeature/web-sdk": "^0.4.11" | ||
}, | ||
@@ -25,3 +29,3 @@ "scripts": { | ||
}, | ||
"gitHead": "f2461b20ffca3c56183193856fe529542e880be7" | ||
"gitHead": "86023f5a9cb5c641213ae7754be2395174754119" | ||
} |
@@ -28,3 +28,3 @@ # OpenFeature Web SDK JavaScript Confidence Provider | ||
import { createConfidenceWebProvider } from '@spotify-confidence/openfeature-web-provider'; | ||
import { OpenFeature, OpenFeatureAPI } from '@openfeature/web-sdk'; | ||
import { OpenFeature } from '@openfeature/web-sdk'; | ||
@@ -37,7 +37,8 @@ const provider = createConfidenceWebProvider({ | ||
await OpenFeature.setContext({ | ||
OpenFeature.setContext({ | ||
targetingKey: 'myTargetingKey', | ||
}); | ||
OpenFeature.setProvider(provider); | ||
await OpenFeature.setProviderAndWait(provider); | ||
const client = OpenFeature.getClient(); | ||
@@ -49,4 +50,3 @@ const result = client.getBooleanValue('flag.my-boolean', false); | ||
- It's advised not to perform `setContext` while `setProvider` is running, you can await setting the context first, or listen to the `ProviderEvent.Ready` via a handler on `OpenFeaure`. | ||
- 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. | ||
- In the above example we first set the context and then set the provider and await for the provider to become ready before getting flags values. Other ways of arranging these calls might make more sense depending on what app framework you are using. See the example apps for more inspiration. | ||
@@ -53,0 +53,0 @@ ## Region |
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
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
191637
2
748
+ Added@spotify-confidence/client-http@0.1.5(transitive)
+ Added@spotify-confidence/sdk@0.0.2(transitive)
- Removed@spotify-confidence/client-http@0.1.6(transitive)