Skip to content

Commit d9a704e

Browse files
committed
fixup: pr feedback from lukas
Signed-off-by: Todd Baert <[email protected]>
1 parent c939571 commit d9a704e

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type { FlagEvaluationOptions } from '../../evaluation';
2424
import type { ProviderEvents } from '../../events';
2525
import type { InternalEventEmitter } from '../../events/internal/internal-event-emitter';
2626
import type { Hook } from '../../hooks';
27-
import { OpenFeature } from '../../open-feature';
2827
import type { Provider} from '../../provider';
2928
import { ProviderStatus } from '../../provider';
3029
import type { Client } from './../client';
@@ -54,6 +53,9 @@ export class OpenFeatureClient implements Client {
5453
private readonly providerAccessor: () => Provider,
5554
private readonly providerStatusAccessor: () => ProviderStatus,
5655
private readonly emitterAccessor: () => InternalEventEmitter,
56+
private readonly apiContextAccessor: () => EvaluationContext,
57+
private readonly apiHooksAccessor: () => Hook[],
58+
private readonly transactionContextAccessor: () => EvaluationContext,
5759
private readonly globalLogger: () => Logger,
5860
private readonly options: OpenFeatureClientOptions,
5961
context: EvaluationContext = {},
@@ -256,7 +258,7 @@ export class OpenFeatureClient implements Client {
256258
// merge global, client, and evaluation context
257259

258260
const allHooks = [
259-
...OpenFeature.getHooks(),
261+
...this.apiHooksAccessor(),
260262
...this.getHooks(),
261263
...(options.hooks || []),
262264
...(this._provider.hooks || []),
@@ -390,8 +392,8 @@ export class OpenFeatureClient implements Client {
390392
private mergeContexts(invocationContext: EvaluationContext) {
391393
// merge global and client contexts
392394
return {
393-
...OpenFeature.getContext(),
394-
...OpenFeature.getTransactionContext(),
395+
...this.apiContextAccessor(),
396+
...this.transactionContextAccessor(),
395397
...this._context,
396398
...invocationContext,
397399
};

packages/server/src/open-feature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ export class OpenFeatureAPI
198198
() => this.getProviderForClient(domain),
199199
() => this.getProviderStatus(domain),
200200
() => this.buildAndCacheEventEmitterForClient(domain),
201+
() => this.getContext(),
202+
() => this.getHooks(),
203+
() => this.getTransactionContext(),
201204
() => this._logger,
202205
{ domain, version },
203206
context,

packages/server/src/provider/provider.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
EvaluationContext,
44
JsonValue,
55
Logger,
6-
TrackingEventDetails,
76
ResolutionDetails} from '@openfeature/core';
87
import {
98
ServerProviderStatus,
@@ -66,12 +65,4 @@ export interface Provider extends CommonProvider<ServerProviderStatus> {
6665
context: EvaluationContext,
6766
logger: Logger,
6867
): Promise<ResolutionDetails<T>>;
69-
70-
/**
71-
* Track a user action or application state, usually representing a business objective or outcome.
72-
* @param trackingEventName
73-
* @param context
74-
* @param trackingEventDetails
75-
*/
76-
track?(trackingEventName: string, context?: EvaluationContext, trackingEventDetails?: TrackingEventDetails): void;
7768
}

packages/shared/src/provider/provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { EvaluationContext } from '../evaluation';
22
import type { AnyProviderEvent, ProviderEventEmitter } from '../events';
3+
import type { TrackingEventDetails } from '../tracking';
34
import type { Metadata, Paradigm } from '../types';
45

56
// TODO: with TypeScript 5+, we can use computed string properties,
@@ -125,4 +126,12 @@ export interface CommonProvider<S extends ClientProviderStatus | ServerProviderS
125126
* @param context
126127
*/
127128
initialize?(context?: EvaluationContext): Promise<void>;
129+
130+
/**
131+
* Track a user action or application state, usually representing a business objective or outcome.
132+
* @param trackingEventName
133+
* @param context
134+
* @param trackingEventDetails
135+
*/
136+
track?(trackingEventName: string, context?: EvaluationContext, trackingEventDetails?: TrackingEventDetails): void;
128137
}

packages/web/src/client/internal/open-feature-client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type { FlagEvaluationOptions } from '../../evaluation';
2424
import type { ProviderEvents } from '../../events';
2525
import type { InternalEventEmitter } from '../../events/internal/internal-event-emitter';
2626
import type { Hook } from '../../hooks';
27-
import { OpenFeature } from '../../open-feature';
2827
import type { Provider} from '../../provider';
2928
import { ProviderStatus } from '../../provider';
3029
import type { Client } from './../client';
@@ -53,6 +52,8 @@ export class OpenFeatureClient implements Client {
5352
private readonly providerAccessor: () => Provider,
5453
private readonly providerStatusAccessor: () => ProviderStatus,
5554
private readonly emitterAccessor: () => InternalEventEmitter,
55+
private readonly apiContextAccessor: (domain?: string) => EvaluationContext,
56+
private readonly apiHooksAccessor: () => Hook[],
5657
private readonly globalLogger: () => Logger,
5758
private readonly options: OpenFeatureClientOptions,
5859
) {}
@@ -189,7 +190,7 @@ export class OpenFeatureClient implements Client {
189190
if (typeof this._provider.track === 'function') {
190191
// copy and freeze the context
191192
const frozenContext = Object.freeze({
192-
...OpenFeature.getContext(this?.options?.domain),
193+
...this.apiContextAccessor(this?.options?.domain),
193194
});
194195
return this._provider.track?.(occurrenceKey, frozenContext, occurrenceDetails);
195196
} else {
@@ -210,15 +211,15 @@ export class OpenFeatureClient implements Client {
210211
// merge global, client, and evaluation context
211212

212213
const allHooks = [
213-
...OpenFeature.getHooks(),
214+
...this.apiHooksAccessor(),
214215
...this.getHooks(),
215216
...(options.hooks || []),
216217
...(this._provider.hooks || []),
217218
];
218219
const allHooksReversed = [...allHooks].reverse();
219220

220221
const context = {
221-
...OpenFeature.getContext(this?.options?.domain),
222+
...this.apiContextAccessor(this?.options?.domain),
222223
};
223224

224225
// this reference cannot change during the course of evaluation

packages/web/src/open-feature.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ export class OpenFeatureAPI
342342
() => this.getProviderForClient(domain),
343343
() => this.getProviderStatus(domain),
344344
() => this.buildAndCacheEventEmitterForClient(domain),
345+
(domain?: string) => this.getContext(domain),
346+
() => this.getHooks(),
345347
() => this._logger,
346348
{ domain, version },
347349
);

packages/web/src/provider/provider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { CommonProvider, EvaluationContext, JsonValue, Logger, TrackingEventDetails, ResolutionDetails } from '@openfeature/core';
1+
import type {
2+
CommonProvider,
3+
EvaluationContext,
4+
JsonValue,
5+
Logger,
6+
ResolutionDetails,
7+
} from '@openfeature/core';
28
import { ClientProviderStatus } from '@openfeature/core';
39
import type { Hook } from '../hooks';
410

@@ -72,12 +78,4 @@ export interface Provider extends CommonProvider<ClientProviderStatus> {
7278
context: EvaluationContext,
7379
logger: Logger,
7480
): ResolutionDetails<T>;
75-
76-
/**
77-
* Track a user action or application state, usually representing a business objective or outcome.
78-
* @param trackingEventName
79-
* @param context
80-
* @param trackingEventDetails
81-
*/
82-
track?(trackingEventName: string, context?: EvaluationContext, trackingEventDetails?: TrackingEventDetails): void;
8381
}

0 commit comments

Comments
 (0)