From 9bf85c7abc123a26fcab5eebd8c2ad7ef29162dc Mon Sep 17 00:00:00 2001 From: Bill Lynch Date: Mon, 23 Oct 2023 10:26:09 +0100 Subject: [PATCH] fixup! fixup! refactor(client-http,web,server): use a serializable and more simple configuration object --- .../client-http/src/client/Configuration.ts | 25 ++++++++++--------- .../src/ConfidenceServerProvider.ts | 3 ++- .../src/ConfidenceWebProvider.ts | 3 ++- yarn.lock | 13 ++++++++++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/client-http/src/client/Configuration.ts b/packages/client-http/src/client/Configuration.ts index 973135a6..a8215066 100644 --- a/packages/client-http/src/client/Configuration.ts +++ b/packages/client-http/src/client/Configuration.ts @@ -30,18 +30,6 @@ export namespace Configuration { } export namespace FlagValue { - function valueMatchesSchema(value: any, schema: FlagSchema): boolean { - if (value === null || schema === null) { - return false; - } - - if (typeof schema !== 'object') { - return typeof value === schema; - } - - return Object.keys(value).every(key => valueMatchesSchema(value[key], schema[key])); - } - export function matches({ schema }: FlagValue, value: any): value is T { return valueMatchesSchema(value, schema); } @@ -73,6 +61,19 @@ export namespace Configuration { } } } + +function valueMatchesSchema(value: any, schema: Configuration.FlagSchema): boolean { + if (value === null || schema === null) { + return false; + } + + if (typeof schema !== 'object') { + return typeof value === schema; + } + + return Object.keys(value).every(key => valueMatchesSchema(value[key], schema[key])); +} + export interface Configuration { flags: Readonly<{ [name: string]: Configuration.Flag; diff --git a/packages/openfeature-server-provider/src/ConfidenceServerProvider.ts b/packages/openfeature-server-provider/src/ConfidenceServerProvider.ts index c5794c48..90657952 100644 --- a/packages/openfeature-server-provider/src/ConfidenceServerProvider.ts +++ b/packages/openfeature-server-provider/src/ConfidenceServerProvider.ts @@ -170,6 +170,7 @@ function mapConfidenceReason(reason: Configuration.ResolveReason): ResolutionRea return 'UNKNOWN'; case Configuration.ResolveReason.Match: return 'TARGETING_MATCH'; + default: + return 'DEFAULT'; } - return 'DEFAULT'; } diff --git a/packages/openfeature-web-provider/src/ConfidenceWebProvider.ts b/packages/openfeature-web-provider/src/ConfidenceWebProvider.ts index c1527ac0..926aa00a 100644 --- a/packages/openfeature-web-provider/src/ConfidenceWebProvider.ts +++ b/packages/openfeature-web-provider/src/ConfidenceWebProvider.ts @@ -205,6 +205,7 @@ function mapConfidenceReason(reason: Configuration.ResolveReason): ResolutionRea return 'UNKNOWN'; case Configuration.ResolveReason.Match: return 'TARGETING_MATCH'; + default: + return 'DEFAULT'; } - return 'DEFAULT'; } diff --git a/yarn.lock b/yarn.lock index 49898c50..7e96d8dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2668,6 +2668,19 @@ dependencies: "@sinonjs/commons" "^1.7.0" +"@spotify-confidence/integration-react@^0.0.4": + version "0.0.4" + resolved "https://registry.yarnpkg.com/@spotify-confidence/integration-react/-/integration-react-0.0.4.tgz#383afc78c2db608b1bf75cb41c53d17512b6a77d" + integrity sha512-4NPbuMTweAz8sjsiEdFNBcB7im5XeETDc7ysyoLWw3vSN407fww+e3XDDhon+advI47TYvlUdvlEN75mOGnW4g== + +"@spotify-confidence/openfeature-server-provider@^0.0.3": + version "0.0.3" + resolved "https://registry.yarnpkg.com/@spotify-confidence/openfeature-server-provider/-/openfeature-server-provider-0.0.3.tgz#e424b2626f291037c00133171a01c4915981b6d4" + integrity sha512-GaOyWe8yOC//LYHe+K3pn2wXUph88doXoLOz/6nup+J/xDc2F7kQIsFkA+TE+fI27CH8iaPUbO8ledTdKcYFjw== + dependencies: + "@spotify-confidence/client-http" "^0.0.2" + fast-deep-equal "^3.1.3" + "@spotify/eslint-config-base@^15.0.0": version "15.0.0" resolved "https://registry.yarnpkg.com/@spotify/eslint-config-base/-/eslint-config-base-15.0.0.tgz#fa8a003e656b1c14694528a487bb9e974e013e4d"