Skip to content

Commit c914326

Browse files
committed
feat: implement tracking as per spec
Signed-off-by: Todd Baert <[email protected]>
1 parent 7257b82 commit c914326

File tree

20 files changed

+112
-15
lines changed

20 files changed

+112
-15
lines changed

packages/angular/angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"cli": {
4040
"schematicCollections": [
4141
"@angular-eslint/schematics"
42-
]
42+
],
43+
"analytics": false
4344
}
4445
}

packages/server/src/client/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
import { Features } from '../evaluation';
99
import { ProviderStatus } from '../provider';
1010
import { ProviderEvents } from '../events';
11+
import { Tracking } from '../tracking';
1112

1213
export interface Client
1314
extends EvaluationLifeCycle<Client>,
1415
Features,
1516
ManageContext<Client>,
1617
ManageLogger<Client>,
18+
Tracking,
1719
Eventing<ProviderEvents> {
1820
readonly metadata: ClientMetadata;
1921
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
HookContext,
1010
JsonValue,
1111
Logger,
12+
OccurrenceDetails,
1213
OpenFeatureError,
1314
ProviderFatalError,
1415
ProviderNotReadyError,
@@ -221,6 +222,10 @@ export class OpenFeatureClient implements Client {
221222
return this.evaluate<T>(flagKey, this._provider.resolveObjectEvaluation, defaultValue, 'object', context, options);
222223
}
223224

225+
track(occurrenceKey: string, context: EvaluationContext, occurrenceDetails: OccurrenceDetails): void {
226+
return this._provider.track?.(occurrenceKey, context, occurrenceDetails);
227+
}
228+
224229
private async evaluate<T extends FlagValue>(
225230
flagKey: string,
226231
resolver: (

packages/server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export * from './open-feature';
55
export * from './transaction-context';
66
export * from './events';
77
export * from './hooks';
8+
export * from './tracking';
89
export * from '@openfeature/core';

packages/server/src/provider/provider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { CommonProvider, EvaluationContext, JsonValue, Logger, ResolutionDetails, ServerProviderStatus } from '@openfeature/core';
1+
import {
2+
CommonProvider,
3+
EvaluationContext,
4+
JsonValue,
5+
Logger,
6+
OccurrenceDetails,
7+
ResolutionDetails,
8+
ServerProviderStatus,
9+
} from '@openfeature/core';
210
import { Hook } from '../hooks';
311

412
export { ServerProviderStatus as ProviderStatus };
@@ -57,4 +65,12 @@ export interface Provider extends CommonProvider<ServerProviderStatus> {
5765
context: EvaluationContext,
5866
logger: Logger,
5967
): Promise<ResolutionDetails<T>>;
68+
69+
/**
70+
* Track a thing
71+
* @param occurrenceKey
72+
* @param context
73+
* @param occurrenceDetails
74+
*/
75+
track?(occurrenceKey: string, context: EvaluationContext, occurrenceDetails: OccurrenceDetails): void;
6076
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './tracking';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { EvaluationContext, OccurrenceDetails } from '@openfeature/core';
2+
3+
export interface Tracking {
4+
5+
/**
6+
* Track a thing
7+
* @param occurrenceKey
8+
* @param context
9+
* @param occurrenceDetails
10+
*/
11+
track(occurrenceKey: string, context: EvaluationContext, occurrenceDetails: OccurrenceDetails): void;
12+
}

packages/shared/src/evaluation/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrimitiveValue } from './evaluation';
1+
import { PrimitiveValue } from '../types';
22

33
export type EvaluationContextValue =
44
| PrimitiveValue

packages/shared/src/evaluation/evaluation.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
export type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
2-
3-
export type PrimitiveValue = null | boolean | string | number;
4-
export type JsonObject = { [key: string]: JsonValue };
5-
export type JsonArray = JsonValue[];
1+
import { JsonValue } from '../types/structure';
62

7-
/**
8-
* Represents a JSON node value.
9-
*/
10-
export type JsonValue = PrimitiveValue | JsonObject | JsonArray;
3+
export type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
114

125
/**
136
* Represents a JSON node value, or Date.

packages/shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export * from './logger';
77
export * from './provider';
88
export * from './evaluation';
99
export * from './type-guards';
10+
export * from './tracking';
1011
export * from './open-feature';

0 commit comments

Comments
 (0)