Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ permissions:
jobs:
sdk-spec:
# Keep the ref in `uses:` and `spec-ref` in sync.
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.3.0
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.7.1
with:
spec-ref: v0.3.0
spec-ref: v0.7.1
tags: core or events or local-evaluation
language: nodejs
50 changes: 49 additions & 1 deletion sdk-spec/steps.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Each function implements the Gherkin step in the comment above it.
*/

import { Flagsmith, type Flags, type FlagsmithValue } from '@flagsmith/nodejs';
import { Flag, Flagsmith, type Flags, type FlagsmithValue } from '@flagsmith/nodejs';

function asSpecFlags(flags: Flags) {
return flags.allFlags().map(flag => ({
Expand All @@ -24,6 +24,20 @@ export function createClientWithLocalEvaluation(environmentKey: string, apiUrl:
return new Flagsmith({ environmentKey, apiUrl, enableLocalEvaluation: true });
}

// Create the SDK client with events enabled
export function createClientWithEvents(
environmentKey: string,
apiUrl: string,
eventsApiUrl: string
) {
return new Flagsmith({
environmentKey,
apiUrl,
enableEvents: true,
eventProcessorConfig: { eventsApiUrl }
});
}

// When the application gets the environment flags
export async function getEnvironmentFlags(flagsmith: Flagsmith) {
return asSpecFlags(await flagsmith.getEnvironmentFlags());
Expand All @@ -37,3 +51,37 @@ export async function getIdentityFlags(
) {
return asSpecFlags(await flagsmith.getIdentityFlags(identifier, traits));
}

// When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits:
export async function getExperimentFlag(
flagsmith: Flagsmith,
feature: string,
identifier: string,
traits: Record<string, FlagsmithValue>
) {
const flag = await flagsmith.getExperimentFlag(feature, identifier, traits);
const featureName = flag instanceof Flag ? flag.featureName : feature; // A default flag has no name of its own
return [{ feature: featureName, enabled: flag.enabled, value: flag.value }];
}

// When the application tracks event "{event}" for identity "{identifier}" with value {value} and metadata:
export function trackEvent(
flagsmith: Flagsmith,
event: string,
identifier: string,
value: FlagsmithValue,
metadata: Record<string, unknown>
) {
flagsmith.trackEvent(event, { identifier, value, metadata });
}

// When the application tracks an exposure of feature "{feature}" for identity "{identifier}" with value {value} and metadata:
export function trackExposureEvent(
flagsmith: Flagsmith,
feature: string,
identifier: string,
value: FlagsmithValue,
metadata: Record<string, unknown>
) {
flagsmith.trackExposureEvent(feature, { identifier, value, metadata });
}
Loading