Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
94e7cb9
fix(launchdarkly-client--README.md): fix typo - options -> ldOptions …
zdunecki Aug 27, 2025
e410263
Add initial implementation of Flagsmith server provider
matthewelwell Sep 3, 2025
9bb904f
Fix export
matthewelwell Sep 3, 2025
8b07394
feat: type-factory-mismatch-returning-undefineds
Zaimwa9 Sep 3, 2025
23c4ddd
feat: implemented-tests-events-and-statuses
Zaimwa9 Sep 5, 2025
abaf152
feat: pass-type-mismatch-error-in-response-instead-of-throwing
Zaimwa9 Sep 15, 2025
115094d
feat: usebooleanconfig-takes-precedence-over-returnvaluefordisabledflags
Zaimwa9 Sep 15, 2025
7c31fa4
feat: removed-unused-import
Zaimwa9 Sep 15, 2025
c9b7241
feat: fixed-flag-not-found-error-panic-error
Zaimwa9 Sep 15, 2025
491dc60
feat: simplified-type-factory
Zaimwa9 Sep 15, 2025
26d4097
feat: added-cause-to-flagsmith-provider-error
Zaimwa9 Sep 15, 2025
016fa0c
feat: Add wrapper information to the LaunchDarkly client-side provide…
kinyoklion Aug 29, 2025
913eec7
chore(config-cat): Update ConfigCat providers to use the new ConfigCa…
adams85 Sep 7, 2025
1bc90aa
fix(security): update dependency axios to v1.12.0 [security] (#1373)
renovate[bot] Sep 14, 2025
4597046
chore(main): release launchdarkly-client-provider 0.3.3 (#1370)
github-actions[bot] Sep 16, 2025
adb1dc8
feat(flagsmith): upgrade-provider-to-latest-flagsmith-client-version …
Zaimwa9 Sep 16, 2025
464e3f9
chore(main): release config-cat-core 0.2.0 (#1346)
github-actions[bot] Sep 18, 2025
6068bd1
chore: update node version (#1377)
beeme1mr Sep 18, 2025
96eef52
fix: publishing pipeline
beeme1mr Sep 18, 2025
b5944e6
chore(main): release config-cat-core 0.2.1 (#1378)
github-actions[bot] Sep 18, 2025
61fc4b6
fix: regenerate the package.json lockfile (#1379)
toddbaert Sep 18, 2025
d573e95
chore(main): release config-cat-core 0.2.2 (#1380)
github-actions[bot] Sep 18, 2025
1886e68
chore(main): release config-cat-provider 0.8.0 (#1383)
github-actions[bot] Sep 19, 2025
931168d
chore(main): release config-cat-web-provider 0.2.0 (#1384)
github-actions[bot] Sep 19, 2025
4f00ef8
refactor(`aws-ssm`): improve unit tests readability (#1363)
gioddiggi Sep 19, 2025
eecf5c1
chore: Revert "chore(main): release config-cat-web-provider 0.2.0" (#…
toddbaert Sep 19, 2025
e01f54d
chore(main): release config-cat-web-provider 0.2.0 (#1386)
github-actions[bot] Sep 19, 2025
02c9a1c
fix: nx affected (#1387)
toddbaert Sep 19, 2025
35b0f18
chore(main): release go-feature-flag-provider 0.7.9 (#1317)
github-actions[bot] Sep 19, 2025
32871d7
feat: updated-errors-to-general-errors
Zaimwa9 Sep 25, 2025
6779c14
feat: added-readme-and-release-please-config
Zaimwa9 Sep 25, 2025
ce592cd
Merge branch 'main' of github.com:Flagsmith/js-sdk-contrib into feat/…
Zaimwa9 Sep 26, 2025
92e60e5
feat: rebase
Zaimwa9 Sep 26, 2025
e90fd0a
feat: added-linter-and-fixes
Zaimwa9 Sep 29, 2025
e42809b
feat: regenerated-lock-file
Zaimwa9 Sep 29, 2025
c3baa8f
feat: moved-flagsmith-node-in-runtime-deps-and-lint-ignored
Zaimwa9 Sep 29, 2025
90ebbb3
feat: regenerated-lockfiles-with-latest-engines
Zaimwa9 Sep 29, 2025
805c26d
feat: install-flagsmith-nodejs-in-root
Zaimwa9 Sep 29, 2025
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
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"libs/shared/config-cat-core": "0.2.2",
"libs/providers/unleash-web": "0.1.1",
"libs/providers/growthbook": "0.1.2",
"libs/providers/aws-ssm": "0.1.3"
"libs/providers/aws-ssm": "0.1.3",
"libs/providers/flagsmith-provider": "0.1.0"
}
29 changes: 29 additions & 0 deletions libs/providers/flagsmith/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "node_modules/**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["flagsmith-nodejs"]
}
]
}
}
]
}
145 changes: 145 additions & 0 deletions libs/providers/flagsmith/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Flagsmith Provider

This is an OpenFeature provider implementation for using [Flagsmith](https://flagsmith.com), a managed feature flag and remote config platform for Node.js applications.

## Installation

```bash
npm install @openfeature/flagsmith-provider @openfeature/server-sdk@^1.19 flagsmith-nodejs@^6.1
```

## Usage

The Flagsmith provider uses the [Flagsmith Node.js SDK](https://docs.flagsmith.com/clients/server-side).

It can be created by passing a configured Flagsmith client instance to the `FlagsmithOpenFeatureProvider` constructor.

### Example using the default configuration

```javascript
import { OpenFeature } from '@openfeature/server-sdk';
import FlagsmithOpenFeatureProvider from '@openfeature/flagsmith-provider';
import Flagsmith from 'flagsmith-nodejs';

// Create the Flagsmith client
const flagsmith = new Flagsmith({
environmentKey: '<your_environment_key>',
});

// Create and set the provider
const provider = new FlagsmithOpenFeatureProvider(flagsmith);
await OpenFeature.setProviderAndWait(provider);

// Obtain a client instance and evaluate feature flags
const client = OpenFeature.getClient();

const value = await client.getBooleanValue('my-flag', false, { targetingKey: 'user-123' });
console.log(`my-flag: ${value}`);

// On application shutdown, clean up the OpenFeature provider
await OpenFeature.clearProviders();
```

### Example using custom configuration

```javascript
import { OpenFeature } from '@openfeature/server-sdk';
import FlagsmithOpenFeatureProvider from '@openfeature/flagsmith-provider';
import Flagsmith from 'flagsmith-nodejs';

// Create the Flagsmith client with custom options
const flagsmith = new Flagsmith({
environmentKey: '<your_environment_key>',
enableLocalEvaluation: true,
retries: 3,
});

// Create the provider with custom configuration
const provider = new FlagsmithOpenFeatureProvider(flagsmith, {
returnValueForDisabledFlags: true,
useFlagsmithDefaults: true,
useBooleanConfigValue: false,
});

await OpenFeature.setProviderAndWait(provider);

// ...
```

## Configuration Options

The provider accepts the following configuration options:

| Option | Type | Default | Description |
| ----------------------------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `returnValueForDisabledFlags` | `boolean` | `false` | If `true`, returns flag values even when disabled. If `false`, throws error for disabled flags (except boolean flags which return `false` with reason `DISABLED` when `useBooleanConfigValue=false`) |
| `useFlagsmithDefaults` | `boolean` | `false` | If `true`, allows using Flagsmith default flag values. If `false`, returns default value with error code for missing flags |
| `useBooleanConfigValue` | `boolean` | `false` | If `true`, returns `flag.value` for boolean flags. If `false`, returns `flag.enabled` |

## Evaluation Context

The OpenFeature Evaluation Context is mapped to Flagsmith's identity and traits system.

### Identity Resolution

- If `targetingKey` is provided in the evaluation context, the provider will use `getIdentityFlags()` to retrieve flags for that specific identity
- If no `targetingKey` is provided, the provider will use `getEnvironmentFlags()` to retrieve environment-level flags

### Traits

The `traits` field in the evaluation context is passed directly to Flagsmith as user traits for targeting and segmentation.

#### Example

```javascript
const evaluationContext = {
targetingKey: 'user-123',
traits: {
email: '[email protected]',
plan: 'premium',
age: 25,
},
};

const value = await client.getBooleanValue('premium-feature', false, evaluationContext);
```

## Flag Value Types

The provider supports all OpenFeature flag value types:

- **Boolean**: Returns `flag.enabled` by default, or `flag.value` if `useBooleanConfigValue` is true
- **String**: Returns the flag value as-is if it's a string
- **Number**: Attempts to parse the flag value as a number
- **Object**: Attempts to parse the flag value as JSON

## Error Handling

The provider handles various error scenarios:

- **Flag Not Found**: Returns default value with `FLAG_NOT_FOUND` error code
- **Type Mismatch**: Returns default value with `TYPE_MISMATCH` error code if flag value cannot be converted to requested type
- **Disabled Flags**:
– For boolean flags with `useBooleanConfigValue=false`: returns `false` with reason `DISABLED`
– For other flags: throws `GeneralError` unless `returnValueForDisabledFlags` is `true`
- **General Errors**: Throws `GeneralError` for client communication issues

## Building

Run:

```bash
nx package providers-flagsmith
```

to build the library.

## Running unit tests

Run:

```bash
npx nx run providers-flagsmith:test
```

to execute the unit tests via [Jest](https://jestjs.io).
10 changes: 10 additions & 0 deletions libs/providers/flagsmith/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'providers-flagsmith',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/providers/flagsmith',
};
Loading