diff --git a/.github/workflows/sdk-spec.yml b/.github/workflows/sdk-spec.yml index cfb2ea1..e132b92 100644 --- a/.github/workflows/sdk-spec.yml +++ b/.github/workflows/sdk-spec.yml @@ -11,7 +11,7 @@ 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.0 with: - spec-ref: v0.3.0 + spec-ref: v0.7.0 language: nodejs diff --git a/sdk-spec/steps.mts b/sdk-spec/steps.mts index 9d4b3c8..0137822 100644 --- a/sdk-spec/steps.mts +++ b/sdk-spec/steps.mts @@ -19,6 +19,20 @@ export function createClient(environmentKey: string, apiUrl: string) { return new Flagsmith({ environmentKey, apiUrl }); } +// 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()); @@ -32,3 +46,36 @@ 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 +) { + const flag = await flagsmith.getExperimentFlag(feature, identifier, traits); + return [{ feature, 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 +) { + 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 +) { + flagsmith.trackExposureEvent(feature, { identifier, value, metadata }); +}