Skip to content

Commit

Permalink
fix: remove export of OpenFeatureClient
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Reining <[email protected]>
  • Loading branch information
lukas-reining committed Jan 28, 2024
1 parent a21634d commit 7efad28
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 62 deletions.
1 change: 0 additions & 1 deletion packages/client/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './client';
export * from './open-feature-client';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/open-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,7 +21,7 @@ type OpenFeatureGlobal = {
type NameProviderRecord = {
name?: string;
provider: Provider;
}
};

const _globalThis = globalThis as OpenFeatureGlobal;

Expand Down
62 changes: 32 additions & 30 deletions packages/client/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -128,12 +128,15 @@ describe('OpenFeatureClient', () => {
resolveBooleanEvaluation(): ResolutionDetails<boolean> {
throw new Error('Method not implemented.');
}

resolveStringEvaluation(): ResolutionDetails<string> {
throw new Error('Method not implemented.');
}

resolveNumberEvaluation(): ResolutionDetails<number> {
throw new Error('Method not implemented.');
}

resolveObjectEvaluation<T extends JsonValue>(): ResolutionDetails<T> {
throw new Error('Method not implemented.');
}
Expand Down Expand Up @@ -229,7 +232,7 @@ describe('OpenFeatureClient', () => {
numberFlag,
defaultNumberValue,
{},
{}
{},
);
});
});
Expand All @@ -241,15 +244,15 @@ describe('OpenFeatureClient', () => {
const defaultNumberValue = 4096;
const value: MyRestrictedNumber = client.getNumberValue<MyRestrictedNumber>(
numberFlag,
defaultNumberValue
defaultNumberValue,
);

expect(value).toEqual(NUMBER_VALUE);
expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(
numberFlag,
defaultNumberValue,
{},
{}
{},
);
});
});
Expand Down Expand Up @@ -326,7 +329,7 @@ describe('OpenFeatureClient', () => {
booleanFlag,
defaultBooleanValue,
{},
{}
{},
);
});
});
Expand Down Expand Up @@ -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<JsonValue> = client.getObjectDetails('flag', { key: 'value' });

expect(details).toBeDefined();
});
});
});

describe('Evaluation details structure', () => {
const flagKey = 'number-details';
const defaultValue = 1970;
let details: EvaluationDetails<number>;

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.";
Expand All @@ -438,68 +441,68 @@ 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', () => {
expect(openFeatureErrorDetails.errorCode).toBeTruthy();
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();
expect(nonOpenFeatureErrorDetails.errorCode).toEqual(ErrorCode.GENERAL); // should fall back to GENERAL
});
});
});

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);
});
});
});
});

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',
Expand All @@ -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);
Expand All @@ -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);
});
});
});

3 changes: 2 additions & 1 deletion packages/client/test/open-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './client';
export * from './open-feature-client';
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenFeatureClient> {
export class OpenFeatureClient implements Client {
private _context: EvaluationContext;
private _hooks: Hook[] = [];
private _clientLogger?: Logger;
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/open-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading

0 comments on commit 7efad28

Please sign in to comment.