Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions sdk-spec/steps.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<string, FlagsmithValue>
) {
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<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