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
2 changes: 1 addition & 1 deletion .changeset/browser-opt-in-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@reflag/browser-sdk": major
---

Opt-in entries from `getOptInFlags()` now include the flag's `value` instead of `isEnabled`. The deprecated `getFeatures()` alias is removed; use `getFlags()`.
Opt-in entries from `getOptInFlags()` now have a Boolean `value` instead of `isEnabled`. The deprecated `getFeatures()` alias is removed; use `getFlags()`.
2 changes: 1 addition & 1 deletion .changeset/opt-in-set-from-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"@reflag/react-native-sdk": major
---

`useOptInFlags()` now returns `setOptIn` along with `flags` and `isLoading`. `useSetOptIn()` still works but is deprecated. Opt-in entries now include the flag's `value` instead of `isEnabled`. The deprecated `useFeature()` alias is removed from React and React Native; use `useFlag()`.
`useOptInFlags()` now returns `setOptIn` along with `flags` and `isLoading`. `useSetOptIn()` still works but is deprecated. Opt-in entries now have a Boolean `value` instead of `isEnabled`. The deprecated `useFeature()` alias is removed from React and React Native; use `useFlag()`.
4 changes: 2 additions & 2 deletions packages/browser-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ try {
}
```

Each entry includes the flag's `key`, `name`, `description` and `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `reflag.refresh()` to retry.
Each entry includes the flag's `key`, `name`, `description`, a Boolean `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `reflag.refresh()` to retry.

## Tracking, feedback and events

Expand All @@ -137,7 +137,7 @@ Use `track(eventName, attributes?)`, `feedback(payload)` and `requestFeedback({
- Use the client's `track()` and `requestFeedback()` instead of the flag's.
- `setFlagOverride(key, value)` takes the value directly; pass `undefined` to remove an override.
- `getFlags()` returns all flag values and records a check for each. Replace `getFeatures()` and `getFeature(key)` with `getFlags()` and `getFlag(key)`; the feature-named methods are removed.
- Opt-in entries from `getOptInFlags()` have the flag's `value` instead of `isEnabled`.
- Opt-in entries from `getOptInFlags()` have a Boolean `value` instead of `isEnabled`.
- Remove `fallbackFlags` and pass a default to each read instead, such as `getFlag("huddles", true)`.
- If you bootstrap from the server, upgrade the Node SDK that produces the bootstrap data to v2 at the same time.
- If you generate type declarations, regenerate them with the v2 CLI.
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ export class ReflagClient {
{
key,
...metadata,
value: flag.value,
value: flag.value === true,
} satisfies OptInFlag,
]
: [];
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-sdk/src/flag/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export type OptInFlag = RawFlagOptIn & {
key: string;

/**
* The flag's value for the current context, or `undefined` if it has none.
* Whether the flag is on for the current context. Opt-in flags are always Boolean.
*/
value: FlagValue | undefined;
value: boolean;
};

export type EvaluationError = {
Expand Down
8 changes: 8 additions & 0 deletions packages/browser-sdk/type-tests/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ const fallback: Settings = { model: "quick", limits: [1] };
const _interface: Settings = client.getFlag("settings", fallback);
// @ts-expect-error literal defaults widen to string, not a specific authored variant
const _literal: "quick" = client.getFlag("model", "quick");

for (const flag of client.getOptInFlags()) {
const _on: boolean = flag.value;
// @ts-expect-error opt-in entries use value instead of isEnabled
void flag.isEnabled;
}
// @ts-expect-error getFeatures was removed; use getFlags
client.getFeatures();
4 changes: 2 additions & 2 deletions packages/react-native-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ try {
}
```

Each entry includes the flag's `key`, `name`, `description` and `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.
Each entry includes the flag's `key`, `name`, `description`, a Boolean `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.

Pass `{ suspense: true }` to `useOptInFlags()` to suspend until the list loads. It defaults to the provider's `suspense` prop.

Expand All @@ -203,7 +203,7 @@ See the [Expo](https://github.com/reflagcom/javascript/tree/main/packages/react-
- Replace `useFlag(key, { suspense: true })` with `useFlagSuspense(key)`, and the flag's loading property with `useIsLoading()`.
- `useFeature()` is removed. Use `useFlag()` instead.
- Use the `setOptIn` function returned by `useOptInFlags()`. `useSetOptIn()` still works but is deprecated.
- Opt-in entries have the flag's `value` instead of `isEnabled`.
- Opt-in entries have a Boolean `value` instead of `isEnabled`.
- Remove `fallbackFlags` and pass a default to each read instead, such as `useFlag("huddles", true)`.
- If you bootstrap from the server, upgrade the Node SDK that produces the bootstrap data to v2 at the same time.
- If you generate type declarations, regenerate them with the v2 CLI.
Expand Down
6 changes: 5 additions & 1 deletion packages/react-native-sdk/type-tests/registered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ export function RegisteredNativeContracts() {
mutable.prompt.tone = "detailed";
mutable.methods.push("express");
const { flags, setOptIn } = useOptInFlags();
for (const flag of flags)
for (const flag of flags) {
void setOptIn(flag.key, { optedIn: !flag.userOptedIn });
const _on: boolean = flag.value;
// @ts-expect-error opt-in entries use value instead of isEnabled
void flag.isEnabled;
}
// @ts-expect-error Registered keys constrain native reads.
useFlag("unknown");
// @ts-expect-error Another numeric flag must not permit a wrong-category default.
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ try {
}
```

Each entry includes the flag's `key`, `name`, `description` and `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.
Each entry includes the flag's `key`, `name`, `description`, a Boolean `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.

Pass `{ suspense: true }` to `useOptInFlags()` to suspend until the list loads. It defaults to the provider's `suspense` prop.

Expand All @@ -158,7 +158,7 @@ Pass `{ suspense: true }` to `useOptInFlags()` to suspend until the list loads.
- Replace `useFlag(key, { suspense: true })` with `useFlagSuspense(key)`, and the flag's loading property with `useIsLoading()`.
- `useFeature()` is removed. Use `useFlag()` instead.
- Use the `setOptIn` function returned by `useOptInFlags()`. `useSetOptIn()` still works but is deprecated.
- Opt-in entries have the flag's `value` instead of `isEnabled`.
- Opt-in entries have a Boolean `value` instead of `isEnabled`.
- Remove `fallbackFlags` and pass a default to each read instead, such as `useFlag("huddles", true)`.
- If you bootstrap from the server, upgrade the Node SDK that produces the bootstrap data to v2 at the same time.
- If you generate type declarations, regenerate them with the v2 CLI.
Expand Down
4 changes: 4 additions & 0 deletions packages/react-sdk/test/opt-in-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function GeneratedOptInTypes() {

for (const flag of flags) {
void setOptIn(flag.key, { optedIn: !flag.userOptedIn });
const on: boolean = flag.value;
void on;
// @ts-expect-error opt-in entries use value instead of isEnabled
void flag.isEnabled;
}

// @ts-expect-error generated flag types still reject unknown literal keys
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const sendFeedback = useSendFeedback();
await sendFeedback({ flagKey: "huddles", score: 5 });
```

Each entry includes the flag's `key`, `name`, `description` and `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.
Each entry includes the flag's `key`, `name`, `description`, a Boolean `value`, and whether the user or company has opted in. User and company opt-ins are independent, and the user or company you opt in must have an `id`. `setOptIn()` resolves once the new flag values have loaded. Check `response.ok` and catch errors, as in the example. If the list fails to load, it stays empty; call `useClient().refresh()` to retry.

Set `enableTracking: false` to stop sending checks and events, or `offline` to skip all requests. See [Browser feedback documentation](../browser-sdk/FEEDBACK.md) for prompting/UI options.

Expand All @@ -133,7 +133,7 @@ Registered flags get autocompletion for their keys and type checks for the defau
- Move remote config to a multivariate flag and read it with a default, such as `useFlag("model", "quick")`. Existing remote config isn't converted automatically.
- Use `useTrack()` and `useRequestFeedback()` instead of the flag's `track()` and `requestFeedback()`.
- Use the `setOptIn` function returned by `useOptInFlags()`. `useSetOptIn()` still works but is deprecated.
- Opt-in entries have the flag's `value` instead of `isEnabled`.
- Opt-in entries have a Boolean `value` instead of `isEnabled`.
- Remove `fallbackFlags` and pass a default to each read instead, such as `useFlag("huddles", true)`.
- If you bootstrap from the server, upgrade the Node SDK that produces the bootstrap data to v2 at the same time.
- If you generate type declarations, regenerate them with the v2 CLI.
Expand Down
4 changes: 4 additions & 0 deletions packages/vue-sdk/test/opt-in-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function GeneratedOptInTypes() {

for (const flag of flags.value) {
void setOptIn(flag.key, { optedIn: !flag.userOptedIn });
const on: boolean = flag.value;
void on;
// @ts-expect-error opt-in entries use value instead of isEnabled
void flag.isEnabled;
}

const loading: boolean = isLoading.value;
Expand Down
Loading