Skip to content

Commit a692a32

Browse files
authored
fix!: remove context from client interfaces (#373)
This PR removes the context from the client's API (as per draft spec). --------- Signed-off-by: Todd Baert <[email protected]>
1 parent 6478a8e commit a692a32

File tree

3 files changed

+11
-57
lines changed

3 files changed

+11
-57
lines changed

packages/client/src/client.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SafeLogger } from '@openfeature/shared';
33
import {
44
ApiEvents,
55
ClientMetadata,
6-
ErrorCode, EvaluationContext,
6+
ErrorCode,
77
EvaluationDetails,
88
FlagValue,
99
FlagValueType,
@@ -30,7 +30,6 @@ type HandlerWrapper = {
3030

3131
export class OpenFeatureClient implements Client {
3232
readonly metadata: ClientMetadata;
33-
private _context: EvaluationContext;
3433
private _hooks: Hook[] = [];
3534
private _clientLogger?: Logger;
3635
private _handlerWrappers: HandlerWrapper[] = [];
@@ -41,13 +40,11 @@ export class OpenFeatureClient implements Client {
4140
private readonly providerAccessor: () => Provider & Partial<EventProvider>,
4241
private readonly globalLogger: () => Logger,
4342
options: OpenFeatureClientOptions,
44-
context: EvaluationContext = {}
4543
) {
4644
this.metadata = {
4745
name: options.name,
4846
version: options.version,
4947
} as const;
50-
this._context = context;
5148

5249
this.attachListeners();
5350
window.dispatchEvent(new CustomEvent(ApiEvents.ProviderChanged));
@@ -83,41 +80,36 @@ export class OpenFeatureClient implements Client {
8380
getBooleanValue(
8481
flagKey: string,
8582
defaultValue: boolean,
86-
context?: EvaluationContext,
8783
options?: FlagEvaluationOptions
8884
): boolean {
89-
return this.getBooleanDetails(flagKey, defaultValue, context, options).value;
85+
return this.getBooleanDetails(flagKey, defaultValue, options).value;
9086
}
9187

9288
getBooleanDetails(
9389
flagKey: string,
9490
defaultValue: boolean,
95-
context?: EvaluationContext,
9691
options?: FlagEvaluationOptions
9792
): EvaluationDetails<boolean> {
9893
return this.evaluate<boolean>(
9994
flagKey,
10095
this._provider.resolveBooleanEvaluation,
10196
defaultValue,
10297
'boolean',
103-
context,
10498
options
10599
);
106100
}
107101

108102
getStringValue<T extends string = string>(
109103
flagKey: string,
110104
defaultValue: T,
111-
context?: EvaluationContext,
112105
options?: FlagEvaluationOptions
113106
): T {
114-
return this.getStringDetails<T>(flagKey, defaultValue, context, options).value;
107+
return this.getStringDetails<T>(flagKey, defaultValue, options).value;
115108
}
116109

117110
getStringDetails<T extends string = string>(
118111
flagKey: string,
119112
defaultValue: T,
120-
context?: EvaluationContext,
121113
options?: FlagEvaluationOptions
122114
): EvaluationDetails<T> {
123115
return this.evaluate<T>(
@@ -126,24 +118,21 @@ export class OpenFeatureClient implements Client {
126118
this._provider.resolveStringEvaluation as () => EvaluationDetails<T>,
127119
defaultValue,
128120
'string',
129-
context,
130121
options
131122
);
132123
}
133124

134125
getNumberValue<T extends number = number>(
135126
flagKey: string,
136127
defaultValue: T,
137-
context?: EvaluationContext,
138128
options?: FlagEvaluationOptions
139129
): T {
140-
return this.getNumberDetails(flagKey, defaultValue, context, options).value;
130+
return this.getNumberDetails(flagKey, defaultValue, options).value;
141131
}
142132

143133
getNumberDetails<T extends number = number>(
144134
flagKey: string,
145135
defaultValue: T,
146-
context?: EvaluationContext,
147136
options?: FlagEvaluationOptions
148137
): EvaluationDetails<T> {
149138
return this.evaluate<T>(
@@ -152,40 +141,35 @@ export class OpenFeatureClient implements Client {
152141
this._provider.resolveNumberEvaluation as () => EvaluationDetails<T>,
153142
defaultValue,
154143
'number',
155-
context,
156144
options
157145
);
158146
}
159147

160148
getObjectValue<T extends JsonValue = JsonValue>(
161149
flagKey: string,
162150
defaultValue: T,
163-
context?: EvaluationContext,
164151
options?: FlagEvaluationOptions
165152
): T {
166-
return this.getObjectDetails(flagKey, defaultValue, context, options).value;
153+
return this.getObjectDetails(flagKey, defaultValue, options).value;
167154
}
168155

169156
getObjectDetails<T extends JsonValue = JsonValue>(
170157
flagKey: string,
171158
defaultValue: T,
172-
context?: EvaluationContext,
173159
options?: FlagEvaluationOptions
174160
): EvaluationDetails<T> {
175-
return this.evaluate<T>(flagKey, this._provider.resolveObjectEvaluation, defaultValue, 'object', context, options);
161+
return this.evaluate<T>(flagKey, this._provider.resolveObjectEvaluation, defaultValue, 'object', options);
176162
}
177163

178164
private evaluate<T extends FlagValue>(
179165
flagKey: string,
180166
resolver: (
181167
flagKey: string,
182168
defaultValue: T,
183-
context: EvaluationContext,
184169
logger: Logger
185170
) => ResolutionDetails<T>,
186171
defaultValue: T,
187172
flagType: FlagValueType,
188-
invocationContext: EvaluationContext = {},
189173
options: FlagEvaluationOptions = {}
190174
): EvaluationDetails<T> {
191175
// merge global, client, and evaluation context
@@ -199,11 +183,8 @@ export class OpenFeatureClient implements Client {
199183
const allHooksReversed = [...allHooks].reverse();
200184

201185
// merge global and client contexts
202-
const mergedContext = {
186+
const context = {
203187
...OpenFeature.getContext(),
204-
...OpenFeature.getTransactionContext(),
205-
...this._context,
206-
...invocationContext,
207188
};
208189

209190
// this reference cannot change during the course of evaluation
@@ -214,15 +195,15 @@ export class OpenFeatureClient implements Client {
214195
flagValueType: flagType,
215196
clientMetadata: this.metadata,
216197
providerMetadata: OpenFeature.providerMetadata,
217-
context: mergedContext,
198+
context,
218199
logger: this._logger,
219200
};
220201

221202
try {
222-
const frozenContext = this.beforeHooks(allHooks, hookContext, options);
203+
this.beforeHooks(allHooks, hookContext, options);
223204

224205
// run the referenced resolver, binding the provider.
225-
const resolution = resolver.call(this._provider, flagKey, defaultValue, frozenContext, this._logger);
206+
const resolution = resolver.call(this._provider, flagKey, defaultValue, this._logger);
226207

227208
const evaluationDetails = {
228209
...resolution,

packages/client/src/open-feature.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ export class OpenFeatureAPI extends OpenFeatureCommonAPI {
8989
await this?._provider?.onClose?.();
9090
}
9191

92-
getClient(name?: string, version?: string, context?: EvaluationContext): Client {
92+
getClient(name?: string, version?: string): Client {
9393
return new OpenFeatureClient(
9494
() => this._provider,
9595
() => this._logger,
9696
{ name, version },
97-
context
9897
);
9998
}
10099
}

packages/client/src/types.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export interface Provider extends CommonProvider {
4545
resolveBooleanEvaluation(
4646
flagKey: string,
4747
defaultValue: boolean,
48-
context: EvaluationContext,
4948
logger: Logger
5049
): ResolutionDetails<boolean>;
5150

@@ -55,7 +54,6 @@ export interface Provider extends CommonProvider {
5554
resolveStringEvaluation(
5655
flagKey: string,
5756
defaultValue: string,
58-
context: EvaluationContext,
5957
logger: Logger
6058
): ResolutionDetails<string>;
6159

@@ -65,7 +63,6 @@ export interface Provider extends CommonProvider {
6563
resolveNumberEvaluation(
6664
flagKey: string,
6765
defaultValue: number,
68-
context: EvaluationContext,
6966
logger: Logger
7067
): ResolutionDetails<number>;
7168

@@ -75,7 +72,6 @@ export interface Provider extends CommonProvider {
7572
resolveObjectEvaluation<T extends JsonValue>(
7673
flagKey: string,
7774
defaultValue: T,
78-
context: EvaluationContext,
7975
logger: Logger
8076
): ResolutionDetails<T>;
8177
}
@@ -166,14 +162,12 @@ export interface Features {
166162
*
167163
* @param {string} flagKey The flag key uniquely identifies a particular flag
168164
* @param {boolean} defaultValue The value returned if an error occurs
169-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
170165
* @param {FlagEvaluationOptions} options Additional flag evaluation options
171166
* @returns {boolean} Flag evaluation response
172167
*/
173168
getBooleanValue(
174169
flagKey: string,
175170
defaultValue: boolean,
176-
context?: EvaluationContext,
177171
options?: FlagEvaluationOptions
178172
): boolean;
179173

@@ -182,14 +176,12 @@ export interface Features {
182176
*
183177
* @param {string} flagKey The flag key uniquely identifies a particular flag
184178
* @param {boolean} defaultValue The value returned if an error occurs
185-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
186179
* @param {FlagEvaluationOptions} options Additional flag evaluation options
187180
* @returns {EvaluationDetails<boolean>} Flag evaluation details response
188181
*/
189182
getBooleanDetails(
190183
flagKey: string,
191184
defaultValue: boolean,
192-
context?: EvaluationContext,
193185
options?: FlagEvaluationOptions
194186
): EvaluationDetails<boolean>;
195187

@@ -199,20 +191,17 @@ export interface Features {
199191
* @param {string} flagKey The flag key uniquely identifies a particular flag
200192
* @template {string} T A optional generic argument constraining the string
201193
* @param {T} defaultValue The value returned if an error occurs
202-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
203194
* @param {FlagEvaluationOptions} options Additional flag evaluation options
204195
* @returns {T} Flag evaluation response
205196
*/
206197
getStringValue(
207198
flagKey: string,
208199
defaultValue: string,
209-
context?: EvaluationContext,
210200
options?: FlagEvaluationOptions
211201
): string;
212202
getStringValue<T extends string = string>(
213203
flagKey: string,
214204
defaultValue: T,
215-
context?: EvaluationContext,
216205
options?: FlagEvaluationOptions
217206
): T;
218207

@@ -222,20 +211,17 @@ export interface Features {
222211
* @param {string} flagKey The flag key uniquely identifies a particular flag
223212
* @template {string} T A optional generic argument constraining the string
224213
* @param {T} defaultValue The value returned if an error occurs
225-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
226214
* @param {FlagEvaluationOptions} options Additional flag evaluation options
227215
* @returns {EvaluationDetails<T>} Flag evaluation details response
228216
*/
229217
getStringDetails(
230218
flagKey: string,
231219
defaultValue: string,
232-
context?: EvaluationContext,
233220
options?: FlagEvaluationOptions
234221
): EvaluationDetails<string>;
235222
getStringDetails<T extends string = string>(
236223
flagKey: string,
237224
defaultValue: T,
238-
context?: EvaluationContext,
239225
options?: FlagEvaluationOptions
240226
): EvaluationDetails<T>;
241227

@@ -245,20 +231,17 @@ export interface Features {
245231
* @param {string} flagKey The flag key uniquely identifies a particular flag
246232
* @template {number} T A optional generic argument constraining the number
247233
* @param {T} defaultValue The value returned if an error occurs
248-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
249234
* @param {FlagEvaluationOptions} options Additional flag evaluation options
250235
* @returns {T} Flag evaluation response
251236
*/
252237
getNumberValue(
253238
flagKey: string,
254239
defaultValue: number,
255-
context?: EvaluationContext,
256240
options?: FlagEvaluationOptions
257241
): number
258242
getNumberValue<T extends number = number>(
259243
flagKey: string,
260244
defaultValue: T,
261-
context?: EvaluationContext,
262245
options?: FlagEvaluationOptions
263246
): T;
264247

@@ -268,20 +251,17 @@ export interface Features {
268251
* @param {string} flagKey The flag key uniquely identifies a particular flag
269252
* @template {number} T A optional generic argument constraining the number
270253
* @param {T} defaultValue The value returned if an error occurs
271-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
272254
* @param {FlagEvaluationOptions} options Additional flag evaluation options
273255
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
274256
*/
275257
getNumberDetails(
276258
flagKey: string,
277259
defaultValue: number,
278-
context?: EvaluationContext,
279260
options?: FlagEvaluationOptions
280261
): EvaluationDetails<number>;
281262
getNumberDetails<T extends number = number>(
282263
flagKey: string,
283264
defaultValue: T,
284-
context?: EvaluationContext,
285265
options?: FlagEvaluationOptions
286266
): EvaluationDetails<T>;
287267

@@ -291,20 +271,17 @@ export interface Features {
291271
* @param {string} flagKey The flag key uniquely identifies a particular flag
292272
* @template {JsonValue} T A optional generic argument describing the structure
293273
* @param {T} defaultValue The value returned if an error occurs
294-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
295274
* @param {FlagEvaluationOptions} options Additional flag evaluation options
296275
* @returns {Promise<T>} Flag evaluation response
297276
*/
298277
getObjectValue(
299278
flagKey: string,
300279
defaultValue: JsonValue,
301-
context?: EvaluationContext,
302280
options?: FlagEvaluationOptions
303281
): JsonValue;
304282
getObjectValue<T extends JsonValue = JsonValue>(
305283
flagKey: string,
306284
defaultValue: T,
307-
context?: EvaluationContext,
308285
options?: FlagEvaluationOptions
309286
): T;
310287

@@ -314,20 +291,17 @@ export interface Features {
314291
* @param {string} flagKey The flag key uniquely identifies a particular flag
315292
* @template {JsonValue} T A optional generic argument describing the structure
316293
* @param {T} defaultValue The value returned if an error occurs
317-
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
318294
* @param {FlagEvaluationOptions} options Additional flag evaluation options
319295
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
320296
*/
321297
getObjectDetails(
322298
flagKey: string,
323299
defaultValue: JsonValue,
324-
context?: EvaluationContext,
325300
options?: FlagEvaluationOptions
326301
): EvaluationDetails<JsonValue>;
327302
getObjectDetails<T extends JsonValue = JsonValue>(
328303
flagKey: string,
329304
defaultValue: T,
330-
context?: EvaluationContext,
331305
options?: FlagEvaluationOptions
332306
): EvaluationDetails<T>;
333307
}

0 commit comments

Comments
 (0)