From 7efad28c60db3599e4f0326c972d6a9b02720441 Mon Sep 17 00:00:00 2001 From: Lukas Reining Date: Sun, 28 Jan 2024 00:36:27 +0100 Subject: [PATCH] fix: remove export of OpenFeatureClient Signed-off-by: Lukas Reining --- packages/client/src/client/index.ts | 1 - .../{ => internal}/open-feature-client.ts | 16 ++--- packages/client/src/open-feature.ts | 5 +- packages/client/test/client.spec.ts | 62 ++++++++++--------- packages/client/test/open-feature.spec.ts | 3 +- packages/server/src/client/index.ts | 1 - .../{ => internal}/open-feature-client.ts | 17 +++-- packages/server/src/open-feature.ts | 3 +- packages/server/test/client.spec.ts | 16 ++--- packages/server/test/open-feature.spec.ts | 3 +- 10 files changed, 65 insertions(+), 62 deletions(-) rename packages/client/src/client/{ => internal}/open-feature-client.ts (95%) rename packages/server/src/client/{ => internal}/open-feature-client.ts (95%) diff --git a/packages/client/src/client/index.ts b/packages/client/src/client/index.ts index 9918836359..4f1cce44fa 100644 --- a/packages/client/src/client/index.ts +++ b/packages/client/src/client/index.ts @@ -1,2 +1 @@ export * from './client'; -export * from './open-feature-client'; diff --git a/packages/client/src/client/open-feature-client.ts b/packages/client/src/client/internal/open-feature-client.ts similarity index 95% rename from packages/client/src/client/open-feature-client.ts rename to packages/client/src/client/internal/open-feature-client.ts index dc86f0a504..70cfdca5dd 100644 --- a/packages/client/src/client/open-feature-client.ts +++ b/packages/client/src/client/internal/open-feature-client.ts @@ -14,15 +14,15 @@ import { ResolutionDetails, SafeLogger, StandardResolutionReasons, - statusMatchesEvent + statusMatchesEvent, } from '@openfeature/core'; -import { FlagEvaluationOptions } from '../evaluation'; -import { ProviderEvents } from '../events'; -import { InternalEventEmitter } from '../events/internal/internal-event-emitter'; -import { Hook } from '../hooks'; -import { OpenFeature } from '../open-feature'; -import { Provider } from '../provider'; -import { Client } from './client'; +import { FlagEvaluationOptions } from '../../evaluation'; +import { ProviderEvents } from '../../events'; +import { InternalEventEmitter } from '../../events/internal/internal-event-emitter'; +import { Hook } from '../../hooks'; +import { OpenFeature } from '../../open-feature'; +import { Provider } from '../../provider'; +import { Client } from '../client'; type OpenFeatureClientOptions = { name?: string; diff --git a/packages/client/src/open-feature.ts b/packages/client/src/open-feature.ts index 77e3889db5..d9534c9050 100644 --- a/packages/client/src/open-feature.ts +++ b/packages/client/src/open-feature.ts @@ -6,7 +6,8 @@ import { objectOrUndefined, stringOrUndefined, } from '@openfeature/core'; -import { Client, OpenFeatureClient } from './client'; +import { Client } from './client'; +import { OpenFeatureClient } from './client/internal/open-feature-client'; import { OpenFeatureEventEmitter, ProviderEvents } from './events'; import { Hook } from './hooks'; import { NOOP_PROVIDER, Provider } from './provider'; @@ -20,7 +21,7 @@ type OpenFeatureGlobal = { type NameProviderRecord = { name?: string; provider: Provider; -} +}; const _globalThis = globalThis as OpenFeatureGlobal; diff --git a/packages/client/test/client.spec.ts b/packages/client/test/client.spec.ts index 73ca224a1b..b7d0fab0cb 100644 --- a/packages/client/test/client.spec.ts +++ b/packages/client/test/client.spec.ts @@ -7,12 +7,12 @@ import { JsonObject, JsonValue, OpenFeature, - OpenFeatureClient, Provider, ProviderStatus, ResolutionDetails, StandardResolutionReasons, } from '../src'; +import { OpenFeatureClient } from '../src/client/internal/open-feature-client'; const BOOLEAN_VALUE = true; const STRING_VALUE = 'val'; @@ -128,12 +128,15 @@ describe('OpenFeatureClient', () => { resolveBooleanEvaluation(): ResolutionDetails { throw new Error('Method not implemented.'); } + resolveStringEvaluation(): ResolutionDetails { throw new Error('Method not implemented.'); } + resolveNumberEvaluation(): ResolutionDetails { throw new Error('Method not implemented.'); } + resolveObjectEvaluation(): ResolutionDetails { throw new Error('Method not implemented.'); } @@ -229,7 +232,7 @@ describe('OpenFeatureClient', () => { numberFlag, defaultNumberValue, {}, - {} + {}, ); }); }); @@ -241,7 +244,7 @@ describe('OpenFeatureClient', () => { const defaultNumberValue = 4096; const value: MyRestrictedNumber = client.getNumberValue( numberFlag, - defaultNumberValue + defaultNumberValue, ); expect(value).toEqual(NUMBER_VALUE); @@ -249,7 +252,7 @@ describe('OpenFeatureClient', () => { numberFlag, defaultNumberValue, {}, - {} + {}, ); }); }); @@ -326,7 +329,7 @@ describe('OpenFeatureClient', () => { booleanFlag, defaultBooleanValue, {}, - {} + {}, ); }); }); @@ -375,50 +378,50 @@ describe('OpenFeatureClient', () => { // No generic information exists at runtime, but this test has some value in ensuring the generic args still exist in the typings. const client = OpenFeature.getClient(); const details: ResolutionDetails = client.getObjectDetails('flag', { key: 'value' }); - + expect(details).toBeDefined(); }); }); }); - + describe('Evaluation details structure', () => { const flagKey = 'number-details'; const defaultValue = 1970; let details: EvaluationDetails; - + describe('Normal execution', () => { beforeEach(() => { const client = OpenFeature.getClient(); details = client.getNumberDetails(flagKey, defaultValue); - + expect(details).toBeDefined(); }); - + describe('Requirement 1.4.2, 1.4.3', () => { it('should contain flag value', () => { expect(details.value).toEqual(NUMBER_VALUE); }); }); - + describe('Requirement 1.4.4', () => { it('should contain flag key', () => { expect(details.flagKey).toEqual(flagKey); }); }); - + describe('Requirement 1.4.5', () => { it('should contain flag variant', () => { expect(details.variant).toEqual(NUMBER_VARIANT); }); }); - + describe('Requirement 1.4.6', () => { it('should contain reason', () => { expect(details.reason).toEqual(REASON); }); }); }); - + describe('Abnormal execution', () => { const NON_OPEN_FEATURE_ERROR_MESSAGE = 'A null dereference or something, I dunno.'; const OPEN_FEATURE_ERROR_MESSAGE = "This ain't the flag you're looking for."; @@ -438,14 +441,14 @@ describe('OpenFeatureClient', () => { } as unknown as Provider; const defaultNumberValue = 123; const defaultStringValue = 'hey!'; - + beforeEach(() => { OpenFeature.setProvider(errorProvider); client = OpenFeature.getClient(); nonOpenFeatureErrorDetails = client.getNumberDetails('some-flag', defaultNumberValue); openFeatureErrorDetails = client.getStringDetails('some-flag', defaultStringValue); }); - + describe('Requirement 1.4.7', () => { describe('OpenFeatureError', () => { it('should contain error code', () => { @@ -453,7 +456,7 @@ describe('OpenFeatureClient', () => { expect(openFeatureErrorDetails.errorCode).toEqual(ErrorCode.FLAG_NOT_FOUND); // should get code from thrown OpenFeatureError }); }); - + describe('Non-OpenFeatureError', () => { it('should contain error code', () => { expect(nonOpenFeatureErrorDetails.errorCode).toBeTruthy(); @@ -461,30 +464,30 @@ describe('OpenFeatureClient', () => { }); }); }); - + describe('Requirement 1.4.8', () => { it('should contain error reason', () => { expect(nonOpenFeatureErrorDetails.reason).toEqual(StandardResolutionReasons.ERROR); expect(openFeatureErrorDetails.reason).toEqual(StandardResolutionReasons.ERROR); }); }); - + describe('Requirement 1.4.9', () => { it('must not throw, must return default', () => { nonOpenFeatureErrorDetails = client.getNumberDetails('some-flag', defaultNumberValue); - + expect(nonOpenFeatureErrorDetails).toBeTruthy(); expect(nonOpenFeatureErrorDetails.value).toEqual(defaultNumberValue); }); }); - + describe('Requirement 1.4.12', () => { describe('OpenFeatureError', () => { it('should contain "error" message', () => { expect(openFeatureErrorDetails.errorMessage).toEqual(OPEN_FEATURE_ERROR_MESSAGE); }); }); - + describe('Non-OpenFeatureError', () => { it('should contain "error" message', () => { expect(nonOpenFeatureErrorDetails.errorMessage).toEqual(NON_OPEN_FEATURE_ERROR_MESSAGE); @@ -492,14 +495,14 @@ describe('OpenFeatureClient', () => { }); }); }); - + describe('Requirement 1.4.13, Requirement 1.4.14', () => { it('should return immutable `flag metadata` as defined by the provider', () => { const flagMetadata = { url: 'https://test.dev', version: '1', }; - + const flagMetadataProvider = { metadata: { name: 'flag-metadata', @@ -511,14 +514,14 @@ describe('OpenFeatureClient', () => { }; }), } as unknown as Provider; - + OpenFeature.setProvider(flagMetadataProvider); const client = OpenFeature.getClient(); const response = client.getBooleanDetails('some-flag', false); expect(response.flagMetadata).toBe(flagMetadata); expect(Object.isFrozen(response.flagMetadata)).toBeTruthy(); }); - + it('should return empty `flag metadata` because it was not set by the provider', () => { // The mock provider doesn't contain flag metadata OpenFeature.setProvider(MOCK_PROVIDER); @@ -530,15 +533,14 @@ describe('OpenFeatureClient', () => { }); describe('providerStatus', () => { - it('should return current provider status', ()=> { - OpenFeature.setProvider({ ...MOCK_PROVIDER, status: ProviderStatus.STALE}); + it('should return current provider status', () => { + OpenFeature.setProvider({ ...MOCK_PROVIDER, status: ProviderStatus.STALE }); expect(OpenFeature.getClient().providerStatus).toEqual(ProviderStatus.STALE); }); - it('should return READY if not defined', ()=> { + it('should return READY if not defined', () => { OpenFeature.setProvider(MOCK_PROVIDER); expect(OpenFeature.getClient().providerStatus).toEqual(ProviderStatus.READY); }); }); }); - diff --git a/packages/client/test/open-feature.spec.ts b/packages/client/test/open-feature.spec.ts index e19d3e0714..eeba47ecfa 100644 --- a/packages/client/test/open-feature.spec.ts +++ b/packages/client/test/open-feature.spec.ts @@ -1,5 +1,6 @@ import { Paradigm } from '@openfeature/core'; -import { OpenFeature, OpenFeatureAPI, OpenFeatureClient, Provider, ProviderStatus } from '../src'; +import { OpenFeature, OpenFeatureAPI, Provider, ProviderStatus } from '../src'; +import { OpenFeatureClient } from '../src/client/internal/open-feature-client'; const mockProvider = (config?: { initialStatus?: ProviderStatus; runsOn?: Paradigm }) => { return { diff --git a/packages/server/src/client/index.ts b/packages/server/src/client/index.ts index 9918836359..4f1cce44fa 100644 --- a/packages/server/src/client/index.ts +++ b/packages/server/src/client/index.ts @@ -1,2 +1 @@ export * from './client'; -export * from './open-feature-client'; diff --git a/packages/server/src/client/open-feature-client.ts b/packages/server/src/client/internal/open-feature-client.ts similarity index 95% rename from packages/server/src/client/open-feature-client.ts rename to packages/server/src/client/internal/open-feature-client.ts index dc5ad4bf22..6a119542df 100644 --- a/packages/server/src/client/open-feature-client.ts +++ b/packages/server/src/client/internal/open-feature-client.ts @@ -9,27 +9,26 @@ import { HookContext, JsonValue, Logger, - ManageContext, OpenFeatureError, ResolutionDetails, SafeLogger, StandardResolutionReasons, statusMatchesEvent, } from '@openfeature/core'; -import { FlagEvaluationOptions } from '../evaluation'; -import { ProviderEvents } from '../events'; -import { InternalEventEmitter } from '../events/internal/internal-event-emitter'; -import { Hook } from '../hooks'; -import { OpenFeature } from '../open-feature'; -import { Provider } from '../provider'; -import { Client } from './client'; +import { FlagEvaluationOptions } from '../../evaluation'; +import { ProviderEvents } from '../../events'; +import { InternalEventEmitter } from '../../events/internal/internal-event-emitter'; +import { Hook } from '../../hooks'; +import { OpenFeature } from '../../open-feature'; +import { Provider } from '../../provider'; +import { Client } from '../client'; type OpenFeatureClientOptions = { name?: string; version?: string; }; -export class OpenFeatureClient implements Client, ManageContext { +export class OpenFeatureClient implements Client { private _context: EvaluationContext; private _hooks: Hook[] = []; private _clientLogger?: Logger; diff --git a/packages/server/src/open-feature.ts b/packages/server/src/open-feature.ts index bfcd87cd40..0849940621 100644 --- a/packages/server/src/open-feature.ts +++ b/packages/server/src/open-feature.ts @@ -12,7 +12,8 @@ import { TransactionContext, TransactionContextPropagator, } from './transaction-context'; -import { Client, OpenFeatureClient } from './client'; +import { Client } from './client'; +import { OpenFeatureClient } from './client/internal/open-feature-client'; import { OpenFeatureEventEmitter } from './events'; import { Hook } from './hooks'; diff --git a/packages/server/test/client.spec.ts b/packages/server/test/client.spec.ts index 19c0829b75..e144de3e6f 100644 --- a/packages/server/test/client.spec.ts +++ b/packages/server/test/client.spec.ts @@ -8,7 +8,6 @@ import { JsonObject, JsonValue, OpenFeature, - OpenFeatureClient, Provider, ProviderStatus, ResolutionDetails, @@ -16,6 +15,7 @@ import { TransactionContext, TransactionContextPropagator, } from '../src'; +import { OpenFeatureClient } from '../src/client/internal/open-feature-client'; const BOOLEAN_VALUE = true; const STRING_VALUE = 'val'; @@ -203,7 +203,7 @@ describe('OpenFeatureClient', () => { const defaultStringValue = 'other'; const value: MyRestrictedString = await client.getStringValue( stringFlag, - defaultStringValue + defaultStringValue, ); expect(value).toEqual(STRING_VALUE); @@ -231,7 +231,7 @@ describe('OpenFeatureClient', () => { const defaultNumberValue = 4096; const value: MyRestrictedNumber = await client.getNumberValue( numberFlag, - defaultNumberValue + defaultNumberValue, ); expect(value).toEqual(NUMBER_VALUE); @@ -534,7 +534,7 @@ describe('OpenFeatureClient', () => { flagKey, defaultValue, expect.objectContaining({ transformed: false }), - {} + {}, ); }); }); @@ -570,7 +570,7 @@ describe('OpenFeatureClient', () => { expect.objectContaining({ targetingKey: TARGETING_KEY, }), - expect.anything() + expect.anything(), ); }); }); @@ -596,7 +596,7 @@ describe('OpenFeatureClient', () => { expect.objectContaining({ ...context, }), - expect.anything() + expect.anything(), ); }); }); @@ -666,7 +666,7 @@ describe('OpenFeatureClient', () => { ...invocationContext, ...beforeHookContext, }), - expect.anything() + expect.anything(), ); }); }); @@ -686,7 +686,7 @@ describe('OpenFeatureClient', () => { const client = OpenFeature.getClient(); expect(await client.addHooks().clearHooks().setContext({}).setLogger(console).getBooleanValue('test', true)).toBe( - true + true, ); }); }); diff --git a/packages/server/test/open-feature.spec.ts b/packages/server/test/open-feature.spec.ts index 6241421149..da4b3c4ef9 100644 --- a/packages/server/test/open-feature.spec.ts +++ b/packages/server/test/open-feature.spec.ts @@ -1,5 +1,6 @@ import { Paradigm } from '@openfeature/core'; -import { OpenFeature, OpenFeatureAPI, OpenFeatureClient, Provider, ProviderStatus } from '../src'; +import { OpenFeature, OpenFeatureAPI, Provider, ProviderStatus } from '../src'; +import { OpenFeatureClient } from '../src/client/internal/open-feature-client'; const mockProvider = (config?: { initialStatus?: ProviderStatus; runsOn?: Paradigm }) => { return {