Skip to content
Merged
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: 5 additions & 0 deletions .changeset/cli-rules-openfeature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reflag/cli": patch
---

The coding-agent rules no longer say the OpenFeature providers use SDK v1.
6 changes: 6 additions & 0 deletions .changeset/openfeature-sdk-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@reflag/openfeature-browser-provider": major
"@reflag/openfeature-node-provider": major
---

Use Reflag SDK v2. Boolean flags resolve with `getBooleanValue()`, and multivariate flags resolve with the method that matches their value's type: `getStringValue()`, `getNumberValue()` or `getObjectValue()`. String and object reads no longer return a Boolean flag's Remote config key or payload; move Remote config to a multivariate flag first. Number reads now work. A read returns your default with `TYPE_MISMATCH` when the value has a different JSON type, and with `DEFAULT` when the flag has no value. The Browser provider reports the selected variant's key as `variant`, and updates the client's context on context changes instead of creating a new client.
8 changes: 5 additions & 3 deletions packages/browser-sdk/test/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ describe("framework v1/v2 release isolation", () => {
);
});

test("keeps the unchanged OpenFeature Browser provider on published v1", () => {
expect(openfeature.dependencies["@reflag/browser-sdk"]).toBe("1.7.4");
expect(openfeatureRequire.resolve("@reflag/browser-sdk")).not.toBe(
test("uses workspace v2 for the OpenFeature Browser provider", () => {
expect(openfeature.dependencies["@reflag/browser-sdk"]).toBe(
`^${browser.version}`,
);
expect(openfeatureRequire.resolve("@reflag/browser-sdk")).toBe(
resolve(__dirname, "../dist/reflag-browser-sdk.umd.js"),
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/services/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getCopilotInstructions() {
const rules = /* markdown */ `
# Reflag SDK v2

These instructions apply to the Node.js, Browser, React, Vue and React Native SDKs, version 2. The OpenFeature providers still use SDK v1; don't mix their code or generated types with v2.
These instructions apply to the Node.js, Browser, React, Vue and React Native SDKs, version 2.

## Reading flags

Expand Down
3 changes: 1 addition & 2 deletions packages/flag-evaluation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ rules or a single flag. It returns an object with `evaluateAll(context)` and
`evaluateFlag(context, flagKey)` methods, rather than a callable evaluator.
Publishers and consumers must adopt the collection/reference protocol together.
Node SDK v2 uses the collection evaluator, including in the matching v2 React
bootstrap demo. The OpenFeature Node provider remains pinned to published Node
SDK 1.8.3 and its v1 evaluator.
bootstrap demo and the OpenFeature Node provider.

V1's `evaluateFlagRules`, scalar `evaluate`, `flattenJSON`, `unflattenJSON`, and
value-rule types are removed. There is no v2 one-shot evaluation wrapper.
Expand Down
18 changes: 9 additions & 9 deletions packages/flag-evaluation/test/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe("v1/v2 release isolation", () => {
);
});

it("keeps the unchanged OpenFeature provider on published Node SDK v1", () => {
// Matching the v2 workspace's version would silently link this alias locally.
expect(require.resolve("@reflag/node-sdk-v1/package.json")).not.toBe(
resolve(__dirname, "../../node-sdk/package.json"),
it("moves the OpenFeature provider onto workspace Node SDK v2", () => {
expect(openfeature.dependencies["@reflag/node-sdk"]).toBe(
`^${nodeSdk.version}`,
);
expect(require("@reflag/node-sdk-v1/package.json").version).toBe("1.8.3");
expect(openfeature.dependencies["@reflag/node-sdk-v1"]).toBe(
"npm:@reflag/node-sdk@1.8.3",
);
expect(openfeature.dependencies).not.toHaveProperty("@reflag/node-sdk");
expect(openfeature.dependencies).not.toHaveProperty("@reflag/node-sdk-v1");
expect(
require.resolve("@reflag/node-sdk/package.json", {
paths: [resolve(__dirname, "../../openfeature-node-provider")],
}),
).toBe(resolve(__dirname, "../../node-sdk/package.json"));
});
});
63 changes: 20 additions & 43 deletions packages/openfeature-browser-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const client = OpenFeature.getClient();
// use client
const boolValue = client.getBooleanValue("huddles", false);

// use more complex, dynamic config-enabled functionality.
// read a multivariate flag's value
const feedbackConfig = client.getObjectValue("ask-feedback", {
question: "How are you enjoying this feature?",
});
Expand All @@ -62,58 +62,35 @@ const feedbackConfig = client.getObjectValue("ask-feedback", {
Initializing the Reflag Browser Provider will
also initialize [automatic feedback surveys](https://github.com/reflagcom/javascript/tree/main/packages/browser-sdk#qualitative-feedback).

## Feature resolution methods
## Flag resolution methods

The Reflag OpenFeature Provider implements the OpenFeature evaluation interface for different value types. Each method handles the resolution of flags according to the OpenFeature specification.

### Common behavior

All resolution methods share these behaviors:

- Return default value with `PROVIDER_NOT_READY` if client is not initialized,
- Return default value with `FLAG_NOT_FOUND` if flag doesn't exist,
- Return default value with `ERROR` if there was a type mismatch,
- Return evaluated value with `TARGETING_MATCH` on successful resolution.

### Type-Specific Methods

#### Boolean Resolution

```ts
client.getBooleanValue("my-flag", false);
```

Returns the flag's enabled state. This is the most common use case for flags.

#### String Resolution
The provider reads flags with Reflag SDK v2. Boolean flags resolve with `getBooleanValue()`. Multivariate flags resolve with the method that matches their value's JSON type.

```ts
client.getStringValue("my-flag", "default");
client.getBooleanValue("huddles", false); // a Boolean flag
client.getStringValue("model", "quick"); // a multivariate flag with string values
client.getNumberValue("max-participants", 10); // ... with number values
client.getObjectValue("huddle-settings", { maxParticipants: 10 }); // ... with object or array values
```

Returns the flag's remote config key (also known as "variant"). Useful for multi-variate use cases.

#### Number Resolution

```ts
client.getNumberValue("my-flag", 0);
```
All methods:

Not directly supported by Reflag. Use `getObjectValue` instead for numeric configurations.
- return the flag's value with `TARGETING_MATCH`. In the Browser provider, `variant` is the key of the selected variant;
- return your default with `DEFAULT` if the flag has no value;
- return your default with `FLAG_NOT_FOUND` if the flag doesn't exist;
- return your default with `TYPE_MISMATCH` if the value has a different JSON type from your default. Pass `null` to `getObjectValue()` to accept any JSON value;
- return your default with `PROVIDER_NOT_READY` before the provider is initialized.

#### Object Resolution
Each evaluation records one check in Reflag.

```ts
// works for any type:
client.getObjectValue("my-flag", { defaultValue: true });
client.getObjectValue("my-flag", "string-value");
client.getObjectValue("my-flag", 199);
```
## Migrating from provider 1.x

Returns the flag's remote config payload with type validation. This is the most flexible method,
allowing for complex configuration objects or simple types.
Version 2 of the provider uses Reflag SDK v2 instead of v1.

The object resolution performs runtime type checking between the default value and the flag payload to ensure type safety.
- `getStringValue()` and `getObjectValue()` read a multivariate flag's value instead of a Boolean flag's Remote config key and payload. Move Remote config to a multivariate flag first. See [Migrating from Remote config](https://docs.reflag.com/product-handbook/multivariate-flags#migrating-from-remote-config).
- `getNumberValue()` now works for multivariate flags with number values.
- A Boolean read of a multivariate flag returns your default with `TYPE_MISMATCH`.
- The `fallbackFlags` option is removed. See the SDK v2 [migration guide](https://docs.reflag.com/supported-languages/migrating-from-v1).

## Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ export async function initOpenFeature() {
console.error("No publishable key set for Reflag");
return;
}
reflagProvider = new ReflagBrowserSDKProvider({
publishableKey,
fallbackFlags: {
huddle: {
key: "zoom", // huddleMeetingProvider
payload: {
joinUrl: "https://zoom.us/join",
},
},
},
});
reflagProvider = new ReflagBrowserSDKProvider({ publishableKey });
return OpenFeature.setProviderAndWait(reflagProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import React from "react";
import { track } from "@/app/featureManagement";

const flagKey = "huddle";
// A multivariate flag whose variants hold the huddle settings.
const settingsFlagKey = "huddle-settings";

export const HuddleFeature = () => {
const isEnabled = useBooleanFlagValue(flagKey, false);
const { variant: huddleMeetingProvider, value: config } =
useObjectFlagDetails(flagKey, {
useObjectFlagDetails(settingsFlagKey, {
joinUrl: "https://zoom.us/join",
});

Expand Down
2 changes: 1 addition & 1 deletion packages/openfeature-browser-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"fmt:fix": "oxfmt --write ."
},
"dependencies": {
"@reflag/browser-sdk": "1.7.4"
"@reflag/browser-sdk": "^2.0.0-next.1"
},
"devDependencies": {
"@openfeature/core": "1.5.0",
Expand Down
Loading
Loading