Skip to content
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

Adds Flagsmith adapter #103

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tiagoapolo
Copy link

@tiagoapolo tiagoapolo commented Mar 13, 2025

This pull request introduces a new provider adapter for the Flags SDK that integrates with Flagsmith. The changes include adding configuration files, updating dependencies, and creating the necessary code for the adapter.

Flagsmith documentation: https://docs.flagsmith.com/clients/next-ssr

Usage

import { createFlagsmithAdapter } from '@flags-sdk/adapter-flagsmith';
import { flag } from 'flags';

// Create the Flagsmith adapter
const flagsmithAdapter = createFlagsmithAdapter({
  environmentID: 'your-environment-id',
  // Optional: Add any other Flagsmith configuration options
  // See: https://docs.flagsmith.com/clients/javascript/
});

// Define your flags
const myFeatureFlag = flag({
  key: 'my-feature',
  adapter: flagsmithAdapter,
});

// Use the flag in your application
const flag = await myFeatureFlag();

Copy link

vercel bot commented Mar 13, 2025

@tiagoapolo is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

socket-security bot commented Mar 13, 2025

New and updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] network 0 618 kB kyle-ssg
npm/[email protected]19.1.0-canary-f457d0b4-20250313 environment 0 163 kB react-bot

View full report↗︎

@tiagoapolo tiagoapolo marked this pull request as ready for review March 14, 2025 14:08
@tiagoapolo tiagoapolo marked this pull request as draft March 14, 2025 14:08
@tiagoapolo tiagoapolo marked this pull request as ready for review March 14, 2025 14:11
Copy link
Collaborator

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contributions so far! I left a bit of early guidance

@@ -0,0 +1,64 @@
# Flags SDK - Flagsmith Provider

A provider adapter for the Flags SDK that integrates with [Flagsmith](https://flagsmith.com/), allowing you to use Flagsmith's feature flags and remote configuration in your application.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you work for Flagsmith? If we merge this PR we'd also put up some actual docs on flags-sdk.dev. Would you be wiling to link to our Flags SDK and those docs from https://docs.flagsmith.com?

// Define your flags
const myFeatureFlag = flag({
key: 'my-feature',
adapter: flagsmithAdapter,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern other adapters follow is this

const myFeatureFlag = flag({
  key: 'my-feature',
  adapter: flagsmithAdapter.getFeature(),
});

Configuring SDKs per feature flag
We are able to pass additional information for that specific flag, for example if the key of the flagsmith flag differed from the key of the Flags SDK flag you could do adapter: flagsmithAdapter.getFeature({ key: "foo" })

Lazy mode
We usually export a default adapter, which is initialized lazily, so people can use the default adapter without any configuration. For this to work, the Flagsmith adapter needs to respect a default set of environment variables, eg FLAGSMITH_ENVIRONMENT_ID.

import { flagsmithAdapter } from "@flags-sdk/flagsmith"

const myFeatureFlag = flag({
  key: 'my-feature',
  adapter: flagsmithAdapter.getFeature(),
})

You can check the implementation of the Statsig/LaunchDarkly adapters as a reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants