Skip to content

Commit 3d197f2

Browse files
fix: remove export of OpenFeatureClient (#794)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR As discussed here #750 (comment), we should not export `OpenFeatureClient` from the server and web SDK. The type used outside the SDK should be `Client`, which is also used in the public APIs like `OpenFeatureApi`. The question is, if we should mark this as breaking. Technically it will break code that imports `OpenFeatureClient` instead of `Client`, but as @toddbaert said code using it could also be seen as "used wrong" while being technically fine. I am still leaning towards marking it as breaking, to be sure we are not breaking something that is technically fine, just because it is unintended use. But I could also live with non-beaking. --------- Signed-off-by: Lukas Reining <[email protected]>
1 parent 7e6c1c6 commit 3d197f2

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

packages/client/src/client/open-feature-client.ts renamed to packages/client/src/client/internal/open-feature-client.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
instantiateErrorByErrorCode,
1919
statusMatchesEvent,
2020
} from '@openfeature/core';
21-
import { FlagEvaluationOptions } from '../evaluation';
22-
import { ProviderEvents } from '../events';
23-
import { InternalEventEmitter } from '../events/internal/internal-event-emitter';
24-
import { Hook } from '../hooks';
25-
import { OpenFeature } from '../open-feature';
26-
import { Provider, ProviderStatus } from '../provider';
27-
import { Client } from './client';
21+
import { FlagEvaluationOptions } from '../../evaluation';
22+
import { ProviderEvents } from '../../events';
23+
import { InternalEventEmitter } from '../../events/internal/internal-event-emitter';
24+
import { Hook } from '../../hooks';
25+
import { OpenFeature } from '../../open-feature';
26+
import { Provider, ProviderStatus } from '../../provider';
27+
import { Client } from './../client';
2828

2929
type OpenFeatureClientOptions = {
3030
/**
@@ -35,6 +35,11 @@ type OpenFeatureClientOptions = {
3535
version?: string;
3636
};
3737

38+
/**
39+
* This implementation of the {@link Client} is meant to only be instantiated by the SDK.
40+
* It should not be used outside the SDK and so should not be exported.
41+
* @internal
42+
*/
3843
export class OpenFeatureClient implements Client {
3944
private _hooks: Hook[] = [];
4045
private _clientLogger?: Logger;

packages/client/src/open-feature.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
stringOrUndefined,
1010
} from '@openfeature/core';
1111
import { Client } from './client';
12+
import { OpenFeatureClient } from './client/internal/open-feature-client';
1213
import { OpenFeatureEventEmitter, ProviderEvents } from './events';
1314
import { Hook } from './hooks';
1415
import { NOOP_PROVIDER, Provider, ProviderStatus } from './provider';
15-
import { OpenFeatureClient } from './client/open-feature-client';
1616

1717
// use a symbol as a key for the global singleton
1818
const GLOBAL_OPENFEATURE_API_KEY = Symbol.for('@openfeature/web-sdk/api');

packages/client/test/client.spec.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ResolutionDetails,
1515
StandardResolutionReasons,
1616
} from '../src';
17-
import { OpenFeatureClient } from '../src/client/open-feature-client';
17+
import { OpenFeatureClient } from '../src/client/internal/open-feature-client';
1818

1919
const BOOLEAN_VALUE = true;
2020
const STRING_VALUE = 'val';
@@ -130,12 +130,15 @@ describe('OpenFeatureClient', () => {
130130
resolveBooleanEvaluation(): ResolutionDetails<boolean> {
131131
throw new Error('Method not implemented.');
132132
}
133+
133134
resolveStringEvaluation(): ResolutionDetails<string> {
134135
throw new Error('Method not implemented.');
135136
}
137+
136138
resolveNumberEvaluation(): ResolutionDetails<number> {
137139
throw new Error('Method not implemented.');
138140
}
141+
139142
resolveObjectEvaluation<T extends JsonValue>(): ResolutionDetails<T> {
140143
throw new Error('Method not implemented.');
141144
}
@@ -236,7 +239,7 @@ describe('OpenFeatureClient', () => {
236239
numberFlag,
237240
defaultNumberValue,
238241
{},
239-
{}
242+
{},
240243
);
241244
});
242245
});
@@ -248,15 +251,15 @@ describe('OpenFeatureClient', () => {
248251
const defaultNumberValue = 4096;
249252
const value: MyRestrictedNumber = client.getNumberValue<MyRestrictedNumber>(
250253
numberFlag,
251-
defaultNumberValue
254+
defaultNumberValue,
252255
);
253256

254257
expect(value).toEqual(NUMBER_VALUE);
255258
expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(
256259
numberFlag,
257260
defaultNumberValue,
258261
{},
259-
{}
262+
{},
260263
);
261264
});
262265
});
@@ -333,7 +336,7 @@ describe('OpenFeatureClient', () => {
333336
booleanFlag,
334337
defaultBooleanValue,
335338
{},
336-
{}
339+
{},
337340
);
338341
});
339342
});
@@ -634,4 +637,3 @@ describe('OpenFeatureClient', () => {
634637
});
635638
});
636639
});
637-

packages/client/test/open-feature.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Paradigm } from '@openfeature/core';
22
import { OpenFeature, OpenFeatureAPI, Provider, ProviderStatus } from '../src';
3-
import { OpenFeatureClient } from '../src/client/open-feature-client';
3+
import { OpenFeatureClient } from '../src/client/internal/open-feature-client';
44

55
const mockProvider = (config?: { initialStatus?: ProviderStatus; runsOn?: Paradigm }) => {
66
return {

packages/server/src/client/open-feature-client.ts renamed to packages/server/src/client/internal/open-feature-client.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
HookContext,
1010
JsonValue,
1111
Logger,
12-
ManageContext,
1312
OpenFeatureError,
1413
ProviderFatalError,
1514
ProviderNotReadyError,
@@ -19,13 +18,13 @@ import {
1918
instantiateErrorByErrorCode,
2019
statusMatchesEvent,
2120
} from '@openfeature/core';
22-
import { FlagEvaluationOptions } from '../evaluation';
23-
import { ProviderEvents } from '../events';
24-
import { InternalEventEmitter } from '../events/internal/internal-event-emitter';
25-
import { Hook } from '../hooks';
26-
import { OpenFeature } from '../open-feature';
27-
import { Provider, ProviderStatus } from '../provider';
28-
import { Client } from './client';
21+
import { FlagEvaluationOptions } from '../../evaluation';
22+
import { ProviderEvents } from '../../events';
23+
import { InternalEventEmitter } from '../../events/internal/internal-event-emitter';
24+
import { Hook } from '../../hooks';
25+
import { OpenFeature } from '../../open-feature';
26+
import { Provider, ProviderStatus } from '../../provider';
27+
import { Client } from './../client';
2928

3029
type OpenFeatureClientOptions = {
3130
/**
@@ -36,7 +35,12 @@ type OpenFeatureClientOptions = {
3635
version?: string;
3736
};
3837

39-
export class OpenFeatureClient implements Client, ManageContext<OpenFeatureClient> {
38+
/**
39+
* This implementation of the {@link Client} is meant to only be instantiated by the SDK.
40+
* It should not be used outside the SDK and so should not be exported.
41+
* @internal
42+
*/
43+
export class OpenFeatureClient implements Client {
4044
private _context: EvaluationContext;
4145
private _hooks: Hook[] = [];
4246
private _clientLogger?: Logger;

packages/server/src/open-feature.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {
33
ManageContext,
44
OpenFeatureCommonAPI,
55
ProviderWrapper,
6+
ServerProviderStatus,
67
objectOrUndefined,
78
stringOrUndefined,
89
} from '@openfeature/core';
910
import { Client } from './client';
11+
import { OpenFeatureClient } from './client/internal/open-feature-client';
1012
import { OpenFeatureEventEmitter } from './events';
1113
import { Hook } from './hooks';
1214
import { NOOP_PROVIDER, Provider, ProviderStatus } from './provider';
@@ -16,8 +18,6 @@ import {
1618
TransactionContext,
1719
TransactionContextPropagator,
1820
} from './transaction-context';
19-
import { ServerProviderStatus } from '@openfeature/core';
20-
import { OpenFeatureClient } from './client/open-feature-client';
2121

2222
// use a symbol as a key for the global singleton
2323
const GLOBAL_OPENFEATURE_API_KEY = Symbol.for('@openfeature/js-sdk/api');

packages/server/test/client.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
TransactionContext,
1818
TransactionContextPropagator,
1919
} from '../src';
20-
import { OpenFeatureClient } from '../src/client/open-feature-client';
20+
import { OpenFeatureClient } from '../src/client/internal/open-feature-client';
2121

2222
const BOOLEAN_VALUE = true;
2323
const STRING_VALUE = 'val';

packages/server/test/open-feature.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Paradigm } from '@openfeature/core';
22
import { OpenFeature, OpenFeatureAPI, Provider, ProviderStatus } from '../src';
3-
import { OpenFeatureClient } from '../src/client/open-feature-client';
3+
import { OpenFeatureClient } from '../src/client/internal/open-feature-client';
44

55
const mockProvider = (config?: { initialStatus?: ProviderStatus; runsOn?: Paradigm }) => {
66
return {

0 commit comments

Comments
 (0)