Skip to content

Commit

Permalink
style(web,client-http,examples): tidy imports and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Billlynch committed Oct 23, 2023
1 parent 9bf85c7 commit 0f4722c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"dependencies": {
"@openfeature/js-sdk": "^1.6.1",
"@spotify-confidence/openfeature-server-provider": "^0.0.3"
"@spotify-confidence/openfeature-server-provider": "^0.0.4"
},
"scripts": {
"dev": "node src/index.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/nodeCJS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"dependencies": {
"@openfeature/js-sdk": "^1.6.1",
"@spotify-confidence/openfeature-server-provider": "^0.0.3"
"@spotify-confidence/openfeature-server-provider": "^0.0.4"
},
"scripts": {
"dev": "node src/index.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/react18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@babel/plugin-syntax-flow": "^7.22.5",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@openfeature/web-sdk": "^0.4.0",
"@spotify-confidence/integration-react": "^0.0.4",
"@spotify-confidence/integration-react": "^0.0.5",
"@spotify-confidence/openfeature-web-provider": "^0.0.3",
"@testing-library/dom": "^7.29.6",
"@testing-library/jest-dom": "^5.14.1",
Expand Down
23 changes: 12 additions & 11 deletions packages/client-http/src/client/ConfidenceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ type ResolveRequest = {
apply?: boolean;
flags?: string[];
};
type ResolveResponse = {
resolvedFlags: ResolvedFlag[];
resolveToken: string;
};
type ConfidenceBaseTypes = { boolSchema: {} } | { doubleSchema: {} } | { intSchema: {} } | { stringSchema: {} };
type ConfidenceFlagSchema = {
schema: {
[key: string]: ConfidenceBaseTypes | { structSchema: ConfidenceFlagSchema };
};
};

export type ResolvedFlag<T = any> = {
flag: string;
variant: string;
value?: T;
flagSchema?: ConfidenceFlagSchema;
reason: Configuration.ResolveReason;
};
type ResolveResponse = {
resolvedFlags: ResolvedFlag[];
resolveToken: string;
};

export type ConfidenceClientOptions = {
fetchImplementation: typeof fetch;
clientSecret: string;
Expand All @@ -35,12 +41,6 @@ export type AppliedFlag = {
flag: string;
applyTime: string;
};
type ConfidenceBaseTypes = { boolSchema: {} } | { doubleSchema: {} } | { intSchema: {} } | { stringSchema: {} };
type ConfidenceFlagSchema = {
schema: {
[key: string]: ConfidenceBaseTypes | { structSchema: ConfidenceFlagSchema };
};
};

export class ConfidenceClient {
private readonly backendApplyEnabled: boolean;
Expand Down Expand Up @@ -123,6 +123,7 @@ function parseBaseType(obj: ConfidenceBaseTypes): Configuration.FlagSchema {

throw new Error(`Confidence: cannot parse schema. unknown schema: ${JSON.stringify(obj)}`);
}

function parseSchema(schema: ConfidenceFlagSchema | undefined): Configuration.FlagSchema {
if (!schema) {
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class ConfidenceWebProvider implements Provider {
}

const [flagName, ...pathParts] = flagKey.split('.');

try {
const flag = this.configuration.flags[flagName];

Expand All @@ -125,12 +126,14 @@ export class ConfidenceWebProvider implements Provider {
reason: 'ERROR',
};
}

if (flagValue.value === null) {
return {
value: defaultValue,
reason: mapConfidenceReason(flag.reason),
};
}

if (!Configuration.FlagValue.matches(flagValue, defaultValue)) {
logger.warn('Value for "%s" is of incorrect type', flagKey);
return {
Expand All @@ -141,6 +144,7 @@ export class ConfidenceWebProvider implements Provider {
}

this.applyManager.apply(this.configuration.resolveToken, flagName);

logger.info('Value for "%s" successfully evaluated', flagKey);
return {
value: flagValue.value as T,
Expand Down
5 changes: 3 additions & 2 deletions packages/openfeature-web-provider/src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Provider } from '@openfeature/web-sdk';
import { ConfidenceWebProvider } from './ConfidenceWebProvider';
import { ConfidenceClient } from '@spotify-confidence/client-http';

export type ConfidenceWebProviderFactoryOptions = {
type ConfidenceWebProviderFactoryOptions = {
region: 'eu' | 'us';
fetchImplementation: typeof fetch;
clientSecret: string;
Expand All @@ -11,7 +12,7 @@ export type ConfidenceWebProviderFactoryOptions = {
};
};

export function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): ConfidenceWebProvider {
export function createConfidenceWebProvider(options: ConfidenceWebProviderFactoryOptions): Provider {
const confidenceClient = new ConfidenceClient({
...options,
apply: !options.apply,
Expand Down
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2668,19 +2668,6 @@
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"
Expand Down

0 comments on commit 0f4722c

Please sign in to comment.