diff --git a/.changeset/browser-opt-in-value.md b/.changeset/browser-opt-in-value.md index 85aa495b..adb3ca08 100644 --- a/.changeset/browser-opt-in-value.md +++ b/.changeset/browser-opt-in-value.md @@ -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()`. diff --git a/.changeset/opt-in-set-from-hook.md b/.changeset/opt-in-set-from-hook.md index 12818bb4..116161d4 100644 --- a/.changeset/opt-in-set-from-hook.md +++ b/.changeset/opt-in-set-from-hook.md @@ -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()`. diff --git a/packages/browser-sdk/README.md b/packages/browser-sdk/README.md index be533175..49b32ab2 100644 --- a/packages/browser-sdk/README.md +++ b/packages/browser-sdk/README.md @@ -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 @@ -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. diff --git a/packages/browser-sdk/src/client.ts b/packages/browser-sdk/src/client.ts index ef66f481..8afccf81 100644 --- a/packages/browser-sdk/src/client.ts +++ b/packages/browser-sdk/src/client.ts @@ -1210,7 +1210,7 @@ export class ReflagClient { { key, ...metadata, - value: flag.value, + value: flag.value === true, } satisfies OptInFlag, ] : []; diff --git a/packages/browser-sdk/src/flag/flags.ts b/packages/browser-sdk/src/flag/flags.ts index 48abdfc8..fdca6295 100644 --- a/packages/browser-sdk/src/flag/flags.ts +++ b/packages/browser-sdk/src/flag/flags.ts @@ -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 = { diff --git a/packages/browser-sdk/type-tests/defaults.ts b/packages/browser-sdk/type-tests/defaults.ts index aa49a877..04af169c 100644 --- a/packages/browser-sdk/type-tests/defaults.ts +++ b/packages/browser-sdk/type-tests/defaults.ts @@ -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(); diff --git a/packages/react-native-sdk/README.md b/packages/react-native-sdk/README.md index 42579e48..a01ecb5e 100644 --- a/packages/react-native-sdk/README.md +++ b/packages/react-native-sdk/README.md @@ -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. @@ -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. diff --git a/packages/react-native-sdk/type-tests/registered.tsx b/packages/react-native-sdk/type-tests/registered.tsx index ae698d7f..0a0626fe 100644 --- a/packages/react-native-sdk/type-tests/registered.tsx +++ b/packages/react-native-sdk/type-tests/registered.tsx @@ -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. diff --git a/packages/react-sdk/README.md b/packages/react-sdk/README.md index b1f636ea..5af65a44 100644 --- a/packages/react-sdk/README.md +++ b/packages/react-sdk/README.md @@ -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. @@ -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. diff --git a/packages/react-sdk/test/opt-in-types.tsx b/packages/react-sdk/test/opt-in-types.tsx index 6b83340f..fe81b748 100644 --- a/packages/react-sdk/test/opt-in-types.tsx +++ b/packages/react-sdk/test/opt-in-types.tsx @@ -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 diff --git a/packages/vue-sdk/README.md b/packages/vue-sdk/README.md index d7f0178d..6cb27867 100644 --- a/packages/vue-sdk/README.md +++ b/packages/vue-sdk/README.md @@ -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. @@ -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. diff --git a/packages/vue-sdk/test/opt-in-types.ts b/packages/vue-sdk/test/opt-in-types.ts index bc7d3ede..af43fc95 100644 --- a/packages/vue-sdk/test/opt-in-types.ts +++ b/packages/vue-sdk/test/opt-in-types.ts @@ -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;