-
Notifications
You must be signed in to change notification settings - Fork 2
Add track and evaluation with details #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| import tape from 'tape-catch'; | ||
|
|
||
| import clientSuite from './nodeSuites/client.spec.js'; | ||
| import providerSuite from './nodeSuites/provider.spec.js'; | ||
|
|
||
| tape('## OpenFeature JavaScript Split Provider - tests', async function (assert) { | ||
| tape('## OpenFeature JavaScript Split Client - tests', async function (assert) { | ||
| assert.test('Client Tests', clientSuite); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| tape('## OpenFeature JavaScript Split Provider - tests', async function (assert) { | ||
| assert.test('Provider Tests', providerSuite); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { | |
| JsonValue, | ||
| TargetingKeyMissingError, | ||
| StandardResolutionReasons, | ||
| TrackingEventDetails, | ||
| } from "@openfeature/server-sdk"; | ||
| import type SplitIO from "@splitsoftware/splitio/types/splitio"; | ||
|
|
||
|
|
@@ -53,16 +54,17 @@ export class OpenFeatureSplitProvider implements Provider { | |
| flagKey, | ||
| this.transformContext(context) | ||
| ); | ||
| const flagName = details.value.toLowerCase(); | ||
|
|
||
| if ( details.value === "on" || details.value === "true" ) { | ||
| if ( flagName === "on" || flagName === "true" ) { | ||
| return { ...details, value: true }; | ||
| } | ||
|
|
||
| if ( details.value === "off" || details.value === "false" ) { | ||
| if ( flagName === "off" || flagName === "false" ) { | ||
| return { ...details, value: false }; | ||
| } | ||
|
|
||
| throw new ParseError(`Invalid boolean value for ${details.value}`); | ||
| throw new ParseError(`Invalid boolean value for ${flagName}`); | ||
| } | ||
|
|
||
| async resolveStringEvaluation( | ||
|
|
@@ -119,7 +121,7 @@ export class OpenFeatureSplitProvider implements Provider { | |
| if (value === CONTROL_TREATMENT) { | ||
| throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE); | ||
| } | ||
| const flagMetadata = config ? JSON.parse(config) : undefined; | ||
| const flagMetadata = { config: config ? config : '' }; | ||
| const details: ResolutionDetails<string> = { | ||
| value: value, | ||
| variant: value, | ||
|
|
@@ -130,6 +132,44 @@ export class OpenFeatureSplitProvider implements Provider { | |
| } | ||
| } | ||
|
|
||
| async track( | ||
| trackingEventName: string, | ||
| context: EvaluationContext, | ||
| details: TrackingEventDetails | ||
| ): Promise<void> { | ||
|
|
||
| // targetingKey is always required | ||
| const { targetingKey } = context; | ||
| if (targetingKey == null || targetingKey === "") | ||
| throw new TargetingKeyMissingError(); | ||
|
|
||
| // eventName is always required | ||
| if (trackingEventName == null || trackingEventName === "") | ||
| throw new ParseError("Missing eventName, required to track"); | ||
|
|
||
| // trafficType is always required | ||
| const ttVal = context["trafficType"]; | ||
| const trafficType = | ||
| ttVal != null && typeof ttVal === "string" && ttVal.trim() !== "" | ||
| ? ttVal | ||
| : null; | ||
| if (trafficType == null || trafficType === "") | ||
| throw new ParseError("Missing trafficType variable, required to track"); | ||
|
|
||
| let value = 0; | ||
|
||
| let properties: SplitIO.Properties = {}; | ||
| if (details != null) { | ||
| if (details.value != null) { | ||
| value = details.value; | ||
| } | ||
| if (details.properties != null) { | ||
| properties = details.properties as SplitIO.Properties; | ||
| } | ||
| } | ||
|
|
||
| this.client.track(targetingKey, trafficType, trackingEventName, value, properties); | ||
| } | ||
|
|
||
| //Transform the context into an object useful for the Split API, an key string with arbitrary Split "Attributes". | ||
| private transformContext(context: EvaluationContext): Consumer { | ||
| const { targetingKey, ...attributes } = context; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flagNamesounds like the feature flag name, but here the variable refers to the treatment value, right? SoflagValueorflagTreatmentare more appropriate names.