@openfeature/react-sdk 0.4.6 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -5
- package/dist/cjs/index.js +78 -35
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +85 -42
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +44 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
<img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.8.0&color=yellow&style=for-the-badge" />
|
|
17
17
|
</a>
|
|
18
18
|
<!-- x-release-please-start-version -->
|
|
19
|
-
<a href="https://github.com/open-feature/js-sdk/releases/tag/react-sdk-v0.4.
|
|
20
|
-
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.
|
|
19
|
+
<a href="https://github.com/open-feature/js-sdk/releases/tag/react-sdk-v0.4.8">
|
|
20
|
+
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.8&color=blue&style=for-the-badge" />
|
|
21
21
|
</a>
|
|
22
22
|
<!-- x-release-please-end -->
|
|
23
23
|
<br/>
|
|
@@ -54,6 +54,7 @@ In addition to the feature provided by the [web sdk](https://openfeature.dev/doc
|
|
|
54
54
|
- [Re-rendering with Context Changes](#re-rendering-with-context-changes)
|
|
55
55
|
- [Re-rendering with Flag Configuration Changes](#re-rendering-with-flag-configuration-changes)
|
|
56
56
|
- [Suspense Support](#suspense-support)
|
|
57
|
+
- [Tracking](#tracking)
|
|
57
58
|
- [Testing](#testing)
|
|
58
59
|
- [FAQ and troubleshooting](#faq-and-troubleshooting)
|
|
59
60
|
- [Resources](#resources)
|
|
@@ -132,7 +133,7 @@ function App() {
|
|
|
132
133
|
|
|
133
134
|
#### Evaluation hooks
|
|
134
135
|
|
|
135
|
-
Within the provider, you can use the various evaluation hooks to evaluate flags.
|
|
136
|
+
Within the provider, you can use the various evaluation hooks to evaluate flags.
|
|
136
137
|
|
|
137
138
|
```tsx
|
|
138
139
|
function Page() {
|
|
@@ -236,7 +237,7 @@ Note that if your provider doesn't support updates, this configuration has no im
|
|
|
236
237
|
|
|
237
238
|
#### Suspense Support
|
|
238
239
|
|
|
239
|
-
> [!NOTE]
|
|
240
|
+
> [!NOTE]
|
|
240
241
|
> React suspense is an experimental feature and subject to change in future versions.
|
|
241
242
|
|
|
242
243
|
|
|
@@ -274,11 +275,32 @@ function Fallback() {
|
|
|
274
275
|
// component to render before READY.
|
|
275
276
|
return <p>Waiting for provider to be ready...</p>;
|
|
276
277
|
}
|
|
277
|
-
|
|
278
278
|
```
|
|
279
279
|
|
|
280
280
|
This can be disabled in the hook options (or in the [OpenFeatureProvider](#openfeatureprovider-context-provider)).
|
|
281
281
|
|
|
282
|
+
#### Tracking
|
|
283
|
+
|
|
284
|
+
The tracking API allows you to use OpenFeature abstractions and objects to associate user actions with feature flag evaluations.
|
|
285
|
+
This is essential for robust experimentation powered by feature flags.
|
|
286
|
+
For example, a flag enhancing the appearance of a UI component might drive user engagement to a new feature; to test this hypothesis, telemetry collected by a [hook](#hooks) or [provider](#providers) can be associated with telemetry reported in the client's `track` function.
|
|
287
|
+
|
|
288
|
+
The React SDK includes a hook for firing tracking events in the <OpenFeatureProvider> context in use:
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
function MyComponent() {
|
|
292
|
+
|
|
293
|
+
// get a tracking function for this <OpenFeatureProvider>.
|
|
294
|
+
const { track } = useTrack();
|
|
295
|
+
|
|
296
|
+
// call the tracking event
|
|
297
|
+
// can be done in render, useEffect, or in handlers, depending on your use case
|
|
298
|
+
track(eventName, trackingDetails);
|
|
299
|
+
|
|
300
|
+
return <>...</>;
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
282
304
|
### Testing
|
|
283
305
|
|
|
284
306
|
The React SDK includes a built-in context provider for testing.
|
package/dist/cjs/index.js
CHANGED
|
@@ -84,6 +84,7 @@ __export(src_exports, {
|
|
|
84
84
|
OpenFeatureTestProvider: () => OpenFeatureTestProvider,
|
|
85
85
|
useBooleanFlagDetails: () => useBooleanFlagDetails,
|
|
86
86
|
useBooleanFlagValue: () => useBooleanFlagValue,
|
|
87
|
+
useContextMutator: () => useContextMutator,
|
|
87
88
|
useFlag: () => useFlag,
|
|
88
89
|
useNumberFlagDetails: () => useNumberFlagDetails,
|
|
89
90
|
useNumberFlagValue: () => useNumberFlagValue,
|
|
@@ -93,6 +94,7 @@ __export(src_exports, {
|
|
|
93
94
|
useStringFlagDetails: () => useStringFlagDetails,
|
|
94
95
|
useStringFlagValue: () => useStringFlagValue,
|
|
95
96
|
useSuspenseFlag: () => useSuspenseFlag,
|
|
97
|
+
useTrack: () => useTrack,
|
|
96
98
|
useWhenProviderReady: () => useWhenProviderReady
|
|
97
99
|
});
|
|
98
100
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -101,6 +103,38 @@ module.exports = __toCommonJS(src_exports);
|
|
|
101
103
|
var import_web_sdk4 = require("@openfeature/web-sdk");
|
|
102
104
|
var import_react4 = require("react");
|
|
103
105
|
|
|
106
|
+
// src/common/context.ts
|
|
107
|
+
var import_react = __toESM(require("react"));
|
|
108
|
+
var Context = import_react.default.createContext(void 0);
|
|
109
|
+
function useProviderOptions() {
|
|
110
|
+
const { options } = import_react.default.useContext(Context) || {};
|
|
111
|
+
return normalizeOptions(options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/common/is-equal.ts
|
|
115
|
+
function isEqual(value, other) {
|
|
116
|
+
if (value === other) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value !== typeof other) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (typeof value === "object" && value !== null && other !== null) {
|
|
123
|
+
const valueKeys = Object.keys(value);
|
|
124
|
+
const otherKeys = Object.keys(other);
|
|
125
|
+
if (valueKeys.length !== otherKeys.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (const key of valueKeys) {
|
|
129
|
+
if (!isEqual(value[key], other[key])) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
104
138
|
// src/common/options.ts
|
|
105
139
|
var DEFAULT_OPTIONS = {
|
|
106
140
|
updateOnContextChanged: true,
|
|
@@ -132,14 +166,6 @@ function suspendUntilReady(client) {
|
|
|
132
166
|
});
|
|
133
167
|
}
|
|
134
168
|
|
|
135
|
-
// src/provider/context.ts
|
|
136
|
-
var import_react = __toESM(require("react"));
|
|
137
|
-
var Context = import_react.default.createContext(void 0);
|
|
138
|
-
function useProviderOptions() {
|
|
139
|
-
const { options } = import_react.default.useContext(Context) || {};
|
|
140
|
-
return normalizeOptions(options);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
169
|
// src/provider/use-open-feature-client.ts
|
|
144
170
|
var import_react2 = __toESM(require("react"));
|
|
145
171
|
function useOpenFeatureClient() {
|
|
@@ -220,30 +246,6 @@ var HookFlagQuery = class {
|
|
|
220
246
|
}
|
|
221
247
|
};
|
|
222
248
|
|
|
223
|
-
// src/common/is-equal.ts
|
|
224
|
-
function isEqual(value, other) {
|
|
225
|
-
if (value === other) {
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
if (typeof value !== typeof other) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
if (typeof value === "object" && value !== null && other !== null) {
|
|
232
|
-
const valueKeys = Object.keys(value);
|
|
233
|
-
const otherKeys = Object.keys(other);
|
|
234
|
-
if (valueKeys.length !== otherKeys.length) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
for (const key of valueKeys) {
|
|
238
|
-
if (!isEqual(value[key], other[key])) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
249
|
// src/evaluation/use-feature-flag.ts
|
|
248
250
|
function useFlag(flagKey, defaultValue, options) {
|
|
249
251
|
const query = typeof defaultValue === "boolean" ? new HookFlagQuery(useBooleanFlagDetails(flagKey, defaultValue, options)) : typeof defaultValue === "number" ? new HookFlagQuery(useNumberFlagDetails(flagKey, defaultValue, options)) : typeof defaultValue === "string" ? new HookFlagQuery(useStringFlagDetails(flagKey, defaultValue, options)) : new HookFlagQuery(useObjectFlagDetails(flagKey, defaultValue, options));
|
|
@@ -304,6 +306,9 @@ function useObjectFlagDetails(flagKey, defaultValue, options) {
|
|
|
304
306
|
options
|
|
305
307
|
);
|
|
306
308
|
}
|
|
309
|
+
function shouldEvaluateFlag(flagKey, flagsChanged) {
|
|
310
|
+
return !!flagsChanged && flagsChanged.includes(flagKey);
|
|
311
|
+
}
|
|
307
312
|
function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
308
313
|
const defaultedOptions = __spreadValues(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), useProviderOptions()), normalizeOptions(options));
|
|
309
314
|
const client = useOpenFeatureClient();
|
|
@@ -327,6 +332,11 @@ function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
|
327
332
|
setEvaluationDetails(updatedEvaluationDetails);
|
|
328
333
|
}
|
|
329
334
|
};
|
|
335
|
+
const configurationChangeCallback = (eventDetails) => {
|
|
336
|
+
if (shouldEvaluateFlag(flagKey, eventDetails == null ? void 0 : eventDetails.flagsChanged)) {
|
|
337
|
+
updateEvaluationDetailsCallback();
|
|
338
|
+
}
|
|
339
|
+
};
|
|
330
340
|
(0, import_react4.useEffect)(() => {
|
|
331
341
|
if (status === import_web_sdk4.ProviderStatus.NOT_READY) {
|
|
332
342
|
client.addHandler(import_web_sdk4.ProviderEvents.Ready, updateEvaluationDetailsCallback);
|
|
@@ -341,10 +351,10 @@ function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
|
341
351
|
}, []);
|
|
342
352
|
(0, import_react4.useEffect)(() => {
|
|
343
353
|
if (defaultedOptions.updateOnConfigurationChanged) {
|
|
344
|
-
client.addHandler(import_web_sdk4.ProviderEvents.ConfigurationChanged,
|
|
354
|
+
client.addHandler(import_web_sdk4.ProviderEvents.ConfigurationChanged, configurationChangeCallback);
|
|
345
355
|
}
|
|
346
356
|
return () => {
|
|
347
|
-
client.removeHandler(import_web_sdk4.ProviderEvents.ConfigurationChanged,
|
|
357
|
+
client.removeHandler(import_web_sdk4.ProviderEvents.ConfigurationChanged, configurationChangeCallback);
|
|
348
358
|
};
|
|
349
359
|
}, []);
|
|
350
360
|
return evaluationDetails;
|
|
@@ -358,7 +368,7 @@ function OpenFeatureProvider(_a) {
|
|
|
358
368
|
if (!client) {
|
|
359
369
|
client = import_web_sdk5.OpenFeature.getClient(domain);
|
|
360
370
|
}
|
|
361
|
-
return /* @__PURE__ */ React3.createElement(Context.Provider, { value: { client, options } }, children);
|
|
371
|
+
return /* @__PURE__ */ React3.createElement(Context.Provider, { value: { client, options, domain } }, children);
|
|
362
372
|
}
|
|
363
373
|
|
|
364
374
|
// src/provider/use-when-provider-ready.ts
|
|
@@ -430,6 +440,39 @@ function mixInNoop(provider = {}) {
|
|
|
430
440
|
return provider;
|
|
431
441
|
}
|
|
432
442
|
|
|
443
|
+
// src/context/use-context-mutator.ts
|
|
444
|
+
var import_react6 = require("react");
|
|
445
|
+
var import_web_sdk8 = require("@openfeature/web-sdk");
|
|
446
|
+
function useContextMutator(options = { defaultContext: false }) {
|
|
447
|
+
const { domain } = (0, import_react6.useContext)(Context) || {};
|
|
448
|
+
const previousContext = (0, import_react6.useRef)(null);
|
|
449
|
+
const setContext = (0, import_react6.useCallback)((updatedContext) => __async(this, null, function* () {
|
|
450
|
+
if (previousContext.current !== updatedContext) {
|
|
451
|
+
if (!domain || (options == null ? void 0 : options.defaultContext)) {
|
|
452
|
+
import_web_sdk8.OpenFeature.setContext(updatedContext);
|
|
453
|
+
} else {
|
|
454
|
+
import_web_sdk8.OpenFeature.setContext(domain, updatedContext);
|
|
455
|
+
}
|
|
456
|
+
previousContext.current = updatedContext;
|
|
457
|
+
}
|
|
458
|
+
}), [domain]);
|
|
459
|
+
return {
|
|
460
|
+
setContext
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/tracking/use-track.ts
|
|
465
|
+
var import_react7 = require("react");
|
|
466
|
+
function useTrack() {
|
|
467
|
+
const client = useOpenFeatureClient();
|
|
468
|
+
const track = (0, import_react7.useCallback)((trackingEventName, trackingEventDetails) => {
|
|
469
|
+
client.track(trackingEventName, trackingEventDetails);
|
|
470
|
+
}, []);
|
|
471
|
+
return {
|
|
472
|
+
track
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
433
476
|
// src/index.ts
|
|
434
477
|
__reExport(src_exports, require("@openfeature/web-sdk"), module.exports);
|
|
435
478
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts", "../../src/evaluation/use-feature-flag.ts", "../../src/common/
|
|
4
|
-
"sourcesContent": ["export * from './evaluation';\nexport * from './query';\nexport * from './provider';\n// re-export the web-sdk so consumers can access that API from the react-sdk\nexport * from '@openfeature/web-sdk';\n", "import {\n Client,\n EvaluationDetails,\n FlagEvaluationOptions,\n FlagValue,\n JsonValue,\n ProviderEvents,\n ProviderStatus,\n} from '@openfeature/web-sdk';\nimport { useEffect, useRef, useState } from 'react';\nimport { DEFAULT_OPTIONS, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\nimport { suspendUntilReady } from '../common/suspense';\nimport { useProviderOptions } from '../provider/context';\nimport { useOpenFeatureClient } from '../provider/use-open-feature-client';\nimport { useOpenFeatureClientStatus } from '../provider/use-open-feature-client-status';\nimport { FlagQuery } from '../query';\nimport { HookFlagQuery } from './hook-flag-query';\nimport { isEqual } from '../common/is-equal';\n\n// This type is a bit wild-looking, but I think we need it.\n// We have to use the conditional, because otherwise useFlag('key', false) would return false, not boolean (too constrained).\n// We have a duplicate for the hook return below, this one is just used for casting because the name isn't as clear\ntype ConstrainedFlagQuery<T> = FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n>;\n\n// suspense options removed for the useSuspenseFlag hooks\ntype NoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>;\n\n/**\n * Evaluates a feature flag generically, returning an react-flavored queryable object.\n * The resolver method to use is based on the type of the defaultValue.\n * For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails} and equivalents.\n * By default, components will re-render when the flag value changes.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {ReactFlagEvaluationOptions} options for this evaluation\n * @returns { FlagQuery } a queryable object containing useful information about the flag.\n */\nexport function useFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n> {\n // use the default value to determine the resolver to call\n const query =\n typeof defaultValue === 'boolean'\n ? new HookFlagQuery<boolean>(useBooleanFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'number'\n ? new HookFlagQuery<number>(useNumberFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'string'\n ? new HookFlagQuery<string>(useStringFlagDetails(flagKey, defaultValue, options))\n : new HookFlagQuery<JsonValue>(useObjectFlagDetails(flagKey, defaultValue, options));\n // TS sees this as HookFlagQuery<JsonValue>, because the compiler isn't aware of the `typeof` checks above.\n return query as unknown as ConstrainedFlagQuery<T>;\n}\n\n// alias to the return value of useFlag, used to keep useSuspenseFlag consistent\ntype UseFlagReturn<T extends FlagValue> = ReturnType<typeof useFlag<T>>;\n\n/**\n * Equivalent to {@link useFlag} with `options: { suspend: true }`\n * @experimental Suspense is an experimental feature subject to change in future versions.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {NoSuspenseOptions} options for this evaluation\n * @returns { UseFlagReturn<T> } a queryable object containing useful information about the flag.\n */\nexport function useSuspenseFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: NoSuspenseOptions,\n): UseFlagReturn<T> {\n return useFlag(flagKey, defaultValue, { ...options, suspendUntilReady: true, suspendWhileReconciling: true });\n}\n\n/**\n * Evaluates a feature flag, returning a boolean.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagValue(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): boolean {\n return useBooleanFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<boolean>} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagDetails(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<boolean> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getBooleanDetails;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a string.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagValue<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): string {\n return useStringFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<string>} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagDetails<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<string> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getStringDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a number.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagValue<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): number {\n return useNumberFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<number>} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagDetails<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<number> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getNumberDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning an object.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagValue<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): T {\n return useObjectFlagDetails<T>(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {T} defaultValue the default value\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<T>} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagDetails<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getObjectDetails<T>;\n },\n options,\n );\n}\n\nfunction attachHandlersAndResolve<T extends FlagValue>(\n flagKey: string,\n defaultValue: T,\n resolver: (\n client: Client,\n ) => (flagKey: string, defaultValue: T, options?: FlagEvaluationOptions) => EvaluationDetails<T>,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n if (defaultedOptions.suspendWhileReconciling && status === ProviderStatus.RECONCILING) {\n suspendUntilReady(client);\n }\n\n const [evaluationDetails, setEvaluationDetails] = useState<EvaluationDetails<T>>(\n resolver(client).call(client, flagKey, defaultValue, options),\n );\n\n // Maintain a mutable reference to the evaluation details to have a up-to-date reference in the handlers.\n const evaluationDetailsRef = useRef<EvaluationDetails<T>>(evaluationDetails);\n useEffect(() => {\n evaluationDetailsRef.current = evaluationDetails;\n }, [evaluationDetails]);\n\n const updateEvaluationDetailsCallback = () => {\n const updatedEvaluationDetails = resolver(client).call(client, flagKey, defaultValue, options);\n\n /**\n * Avoid re-rendering if the value hasn't changed. We could expose a means\n * to define a custom comparison function if users require a more\n * sophisticated comparison in the future.\n */\n if (!isEqual(updatedEvaluationDetails.value, evaluationDetailsRef.current.value)) {\n setEvaluationDetails(updatedEvaluationDetails);\n }\n };\n\n useEffect(() => {\n if (status === ProviderStatus.NOT_READY) {\n // update when the provider is ready\n client.addHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n }\n\n if (defaultedOptions.updateOnContextChanged) {\n // update when the context changes\n client.addHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n client.removeHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n useEffect(() => {\n if (defaultedOptions.updateOnConfigurationChanged) {\n // update when the provider configuration changes\n client.addHandler(ProviderEvents.ConfigurationChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n return evaluationDetails;\n}\n", "import { FlagEvaluationOptions } from '@openfeature/web-sdk';\n\nexport type ReactFlagEvaluationOptions = ({\n /**\n * Enable or disable all suspense functionality.\n * Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspend?: boolean;\n suspendUntilReady?: never;\n suspendWhileReconciling?: never;\n} | {\n /**\n * Suspend flag evaluations while the provider is not ready.\n * Set to false if you don't want to show suspense fallbacks until the provider is initialized.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendUntilReady?: boolean;\n /**\n * Suspend flag evaluations while the provider's context is being reconciled.\n * Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendWhileReconciling?: boolean;\n suspend?: never;\n}) & {\n /**\n * Update the component if the provider emits a ConfigurationChanged event.\n * Set to false to prevent components from re-rendering when flag value changes\n * are received by the associated provider.\n * Defaults to true.\n */\n updateOnConfigurationChanged?: boolean;\n /**\n * Update the component when the OpenFeature context changes.\n * Set to false to prevent components from re-rendering when attributes which\n * may be factors in flag evaluation change.\n * Defaults to true.\n */\n updateOnContextChanged?: boolean;\n} & FlagEvaluationOptions;\n\nexport type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>;\n\n/**\n * Default options.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const DEFAULT_OPTIONS: ReactFlagEvaluationOptions = {\n updateOnContextChanged: true,\n updateOnConfigurationChanged: true,\n suspendUntilReady: false,\n suspendWhileReconciling: false,\n};\n\n/**\n * Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`).\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @param {ReactFlagEvaluationOptions} options options to normalize\n * @returns {NormalizedOptions} normalized options\n */\nexport const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions = (options: ReactFlagEvaluationOptions = {}) => {\n const updateOnContextChanged = options.updateOnContextChanged;\n const updateOnConfigurationChanged = options.updateOnConfigurationChanged;\n\n // fall-back the suspense options to the catch-all `suspend` property \n const suspendUntilReady = 'suspendUntilReady' in options ? options.suspendUntilReady : options.suspend;\n const suspendWhileReconciling = 'suspendWhileReconciling' in options ? options.suspendWhileReconciling : options.suspend;\n\n return {\n // only return these if properly set (no undefined to allow overriding with spread)\n ...(typeof suspendUntilReady === 'boolean' && {suspendUntilReady}),\n ...(typeof suspendWhileReconciling === 'boolean' && {suspendWhileReconciling}),\n ...(typeof updateOnContextChanged === 'boolean' && {updateOnContextChanged}),\n ...(typeof updateOnConfigurationChanged === 'boolean' && {updateOnConfigurationChanged}),\n };\n};\n", "import { Client, ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Suspends until the client is ready to evaluate feature flags.\n * DO NOT EXPORT PUBLICLY\n * @param {Client} client OpenFeature client\n */\nexport function suspendUntilReady(client: Client): Promise<void> {\n let resolve: (value: unknown) => void;\n let reject: () => void;\n throw new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n client.addHandler(ProviderEvents.Ready, resolve);\n client.addHandler(ProviderEvents.Error, reject);\n }).finally(() => {\n client.removeHandler(ProviderEvents.Ready, resolve);\n client.removeHandler(ProviderEvents.Ready, reject);\n });\n}\n", "import { Client } from '@openfeature/web-sdk';\nimport React from 'react';\nimport { NormalizedOptions, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\n\n/**\n * The underlying React context.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const Context = React.createContext<{ client: Client; options: ReactFlagEvaluationOptions } | undefined>(undefined);\n\n/**\n * Get a normalized copy of the options used for this OpenFeatureProvider, see {@link normalizeOptions}.\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @returns {NormalizedOptions} normalized options the defaulted options, not defaulted or normalized.\n */\nexport function useProviderOptions(): NormalizedOptions {\n const { options } = React.useContext(Context) || {};\n return normalizeOptions(options);\n}\n", "import React from 'react';\nimport { Context } from './context';\nimport { Client } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link Client} instance for this OpenFeatureProvider context.\n * Note that the provider to which this is bound is determined by the OpenFeatureProvider's domain.\n * @returns {Client} client for this scope\n */\nexport function useOpenFeatureClient(): Client {\n const { client } = React.useContext(Context) || {};\n\n if (!client) {\n throw new Error(\n 'No OpenFeature client available - components using OpenFeature must be wrapped with an <OpenFeatureProvider>. If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing',\n );\n }\n\n return client;\n}\n", "import { useEffect, useState } from 'react';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { ProviderEvents, ProviderStatus } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link ProviderStatus} for the OpenFeatureClient.\n * @returns {ProviderStatus} status of the client for this scope\n */\nexport function useOpenFeatureClientStatus(): ProviderStatus {\n const client = useOpenFeatureClient();\n const [status, setStatus] = useState(client.providerStatus);\n\n useEffect(() => {\n const updateStatus = () => setStatus(client.providerStatus);\n client.addHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.addHandler(ProviderEvents.ContextChanged, updateStatus);\n client.addHandler(ProviderEvents.Error, updateStatus);\n client.addHandler(ProviderEvents.Ready, updateStatus);\n client.addHandler(ProviderEvents.Stale, updateStatus);\n client.addHandler(ProviderEvents.Reconciling, updateStatus);\n return () => {\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.removeHandler(ProviderEvents.ContextChanged, updateStatus);\n client.removeHandler(ProviderEvents.Error, updateStatus);\n client.removeHandler(ProviderEvents.Ready, updateStatus);\n client.removeHandler(ProviderEvents.Stale, updateStatus);\n client.removeHandler(ProviderEvents.Reconciling, updateStatus);\n };\n }, [client]);\n\n return status;\n}\n", "import {\n EvaluationDetails,\n FlagValue,\n StandardResolutionReasons\n} from '@openfeature/web-sdk';\nimport { FlagQuery } from '../query';\n\n\n// FlagQuery implementation, do not export\nexport class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {\n constructor(private _details: EvaluationDetails<T>) {}\n\n get details() {\n return this._details;\n }\n\n get value() {\n return this._details?.value;\n }\n\n get variant() {\n return this._details.variant;\n }\n\n get flagMetadata() {\n return this._details.flagMetadata;\n }\n\n get reason() {\n return this._details.reason;\n }\n\n get isError() {\n return !!this._details?.errorCode || this._details.reason == StandardResolutionReasons.ERROR;\n }\n\n get errorCode() {\n return this._details?.errorCode;\n }\n\n get errorMessage() {\n return this._details?.errorMessage;\n }\n\n get isAuthoritative() {\n return (\n !this.isError &&\n this._details.reason != StandardResolutionReasons.STALE &&\n this._details.reason != StandardResolutionReasons.DISABLED\n );\n }\n\n get type() {\n return typeof this._details.value;\n }\n}\n", "import { type FlagValue } from '@openfeature/web-sdk';\n\n/**\n * Deeply compare two values to determine if they are equal.\n * Supports primitives and serializable objects.\n * @param {FlagValue} value First value to compare\n * @param {FlagValue} other Second value to compare\n * @returns {boolean} True if the values are equal\n */\nexport function isEqual(value: FlagValue, other: FlagValue): boolean {\n if (value === other) {\n return true;\n }\n\n if (typeof value !== typeof other) {\n return false;\n }\n\n if (typeof value === 'object' && value !== null && other !== null) {\n const valueKeys = Object.keys(value);\n const otherKeys = Object.keys(other);\n\n if (valueKeys.length !== otherKeys.length) {\n return false;\n }\n\n for (const key of valueKeys) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!isEqual((value as any)[key], (other as any)[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n", "import { Client, OpenFeature } from '@openfeature/web-sdk';\nimport * as React from 'react';\nimport { ReactFlagEvaluationOptions } from '../common/options';\nimport { Context } from './context';\n\ntype ClientOrDomain =\n | {\n /**\n * An identifier which logically binds clients with providers\n * @see OpenFeature.setProvider() and overloads.\n */\n domain?: string;\n client?: never;\n }\n | {\n /**\n * OpenFeature client to use.\n */\n client?: Client;\n domain?: never;\n };\n\ntype ProviderProps = {\n children?: React.ReactNode;\n} & ClientOrDomain &\n ReactFlagEvaluationOptions;\n\n /**\n * Provides a scope for evaluating feature flags by binding a client to all child components.\n * @param {ProviderProps} properties props for the context provider\n * @returns {OpenFeatureProvider} context provider\n */\nexport function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps) {\n if (!client) {\n client = OpenFeature.getClient(domain);\n }\n\n return <Context.Provider value={{ client, options }}>{children}</Context.Provider>;\n}\n", "import { ProviderStatus } from '@openfeature/web-sdk';\nimport { DEFAULT_OPTIONS, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\nimport { useProviderOptions } from './context';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { useOpenFeatureClientStatus } from './use-open-feature-client-status';\nimport { suspendUntilReady } from '../common/suspense';\n\ntype Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;\n\n/**\n * Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.\n * Especially useful for React v16/17 \"Legacy Suspense\", in which siblings to suspending components are\n * initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).\n * @param {Options} options options for suspense\n * @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own\n */\nexport function useWhenProviderReady(options?: Options): boolean {\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n return status === ProviderStatus.READY;\n}\n", "import {\n InMemoryProvider,\n JsonValue,\n NOOP_PROVIDER,\n OpenFeature,\n Provider,\n} from '@openfeature/web-sdk';\nimport React from 'react';\nimport { NormalizedOptions } from '../common/options';\nimport { OpenFeatureProvider } from './provider';\n\ntype FlagValueMap = { [flagKey: string]: JsonValue };\ntype FlagConfig = ConstructorParameters<typeof InMemoryProvider>[0];\ntype TestProviderProps = Omit<React.ComponentProps<typeof OpenFeatureProvider>, 'client'> &\n (\n | {\n provider?: never;\n /**\n * Optional map of flagKeys to flagValues for this OpenFeatureTestProvider context.\n * If not supplied, all flag evaluations will default.\n */\n flagValueMap?: FlagValueMap;\n /**\n * Optional delay for the underlying test provider's readiness and reconciliation.\n * Defaults to 0.\n */\n delayMs?: number;\n }\n | {\n /**\n * An optional partial provider to pass for full control over the flag resolution for this OpenFeatureTestProvider context.\n * Any un-implemented methods or properties will no-op.\n */\n provider?: Partial<Provider>;\n flagValueMap?: never;\n delayMs?: never;\n }\n );\n\n const TEST_VARIANT = 'test-variant';\n const TEST_PROVIDER = 'test-provider';\n\n// internal provider which is basically the in-memory provider with a simpler config and some optional fake delays\nclass TestProvider extends InMemoryProvider {\n\n // initially make this undefined, we still set it if a delay is specified\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - For maximum compatibility with previous versions, we ignore a possible TS error here,\n // since \"initialize\" was previously defined in superclass.\n // We can safely remove this ts-ignore in a few versions\n initialize: Provider['initialize'] = undefined;\n\n // \"place-holder\" init function which we only assign if want a delay\n private delayedInitialize = async () => {\n await new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n };\n\n constructor(\n flagValueMap: FlagValueMap,\n private delay = 0,\n ) {\n // convert the simple flagValueMap into an in-memory config\n const flagConfig = Object.entries(flagValueMap).reduce((acc: FlagConfig, flag): FlagConfig => {\n return {\n ...acc,\n [flag[0]]: {\n variants: {\n [TEST_VARIANT]: flag[1],\n },\n defaultVariant: TEST_VARIANT,\n disabled: false,\n },\n };\n }, {});\n super(flagConfig);\n // only define and init if there's a non-zero delay specified\n this.initialize = this.delay ? this.delayedInitialize.bind(this) : undefined;\n }\n\n async onContextChange() {\n return new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n }\n}\n\n/**\n * A React Context provider based on the {@link InMemoryProvider}, specifically built for testing.\n * Use this for testing components that use flag evaluation hooks.\n * @param {TestProviderProps} testProviderOptions options for the OpenFeatureTestProvider\n * @returns {OpenFeatureProvider} OpenFeatureTestProvider\n */\nexport function OpenFeatureTestProvider(testProviderOptions: TestProviderProps) {\n const { flagValueMap, provider } = testProviderOptions;\n const effectiveProvider = (\n flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) || NOOP_PROVIDER\n ) as Provider;\n testProviderOptions.domain\n ? OpenFeature.setProvider(testProviderOptions.domain, effectiveProvider)\n : OpenFeature.setProvider(effectiveProvider);\n\n return (\n <OpenFeatureProvider {...(testProviderOptions as NormalizedOptions)} domain={testProviderOptions.domain}>\n {testProviderOptions.children}\n </OpenFeatureProvider>\n );\n}\n\n// mix in the no-op provider when the partial is passed\nfunction mixInNoop(provider: Partial<Provider> = {}) {\n // fill in any missing methods with no-ops\n for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(NOOP_PROVIDER)).filter(prop => prop !== 'constructor')) {\n const patchedProvider = provider as {[key: string]: keyof Provider};\n if (!Object.getPrototypeOf(patchedProvider)[prop] && !patchedProvider[prop]) {\n patchedProvider[prop] = Object.getPrototypeOf(NOOP_PROVIDER)[prop];\n }\n }\n // fill in the metadata if missing\n if (!provider.metadata || !provider.metadata.name) {\n (provider.metadata as unknown) = { name: TEST_PROVIDER };\n }\n return provider;\n}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
6
|
-
"names": ["import_web_sdk", "import_react", "
|
|
3
|
+
"sources": ["../../src/index.ts", "../../src/evaluation/use-feature-flag.ts", "../../src/common/context.ts", "../../src/common/is-equal.ts", "../../src/common/options.ts", "../../src/common/suspense.ts", "../../src/provider/use-open-feature-client.ts", "../../src/provider/use-open-feature-client-status.ts", "../../src/evaluation/hook-flag-query.ts", "../../src/provider/provider.tsx", "../../src/provider/use-when-provider-ready.ts", "../../src/provider/test-provider.tsx", "../../src/context/use-context-mutator.ts", "../../src/tracking/use-track.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './evaluation';\nexport * from './query';\nexport * from './provider';\nexport * from './context';\nexport * from './tracking';\n// re-export the web-sdk so consumers can access that API from the react-sdk\nexport * from '@openfeature/web-sdk';\n", "import type {\n Client,\n ClientProviderEvents,\n EvaluationDetails,\n EventHandler,\n FlagEvaluationOptions,\n FlagValue,\n JsonValue} from '@openfeature/web-sdk';\nimport {\n ProviderEvents,\n ProviderStatus,\n} from '@openfeature/web-sdk';\nimport { useEffect, useRef, useState } from 'react';\nimport type { ReactFlagEvaluationOptions} from '../common';\nimport { DEFAULT_OPTIONS, isEqual, normalizeOptions, suspendUntilReady, useProviderOptions } from '../common';\nimport { useOpenFeatureClient } from '../provider/use-open-feature-client';\nimport { useOpenFeatureClientStatus } from '../provider/use-open-feature-client-status';\nimport type { FlagQuery } from '../query';\nimport { HookFlagQuery } from './hook-flag-query';\n\n// This type is a bit wild-looking, but I think we need it.\n// We have to use the conditional, because otherwise useFlag('key', false) would return false, not boolean (too constrained).\n// We have a duplicate for the hook return below, this one is just used for casting because the name isn't as clear\ntype ConstrainedFlagQuery<T> = FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n>;\n\n// suspense options removed for the useSuspenseFlag hooks\ntype NoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>;\n\n/**\n * Evaluates a feature flag generically, returning an react-flavored queryable object.\n * The resolver method to use is based on the type of the defaultValue.\n * For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails} and equivalents.\n * By default, components will re-render when the flag value changes.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {ReactFlagEvaluationOptions} options for this evaluation\n * @returns { FlagQuery } a queryable object containing useful information about the flag.\n */\nexport function useFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n> {\n // use the default value to determine the resolver to call\n const query =\n typeof defaultValue === 'boolean'\n ? new HookFlagQuery<boolean>(useBooleanFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'number'\n ? new HookFlagQuery<number>(useNumberFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'string'\n ? new HookFlagQuery<string>(useStringFlagDetails(flagKey, defaultValue, options))\n : new HookFlagQuery<JsonValue>(useObjectFlagDetails(flagKey, defaultValue, options));\n // TS sees this as HookFlagQuery<JsonValue>, because the compiler isn't aware of the `typeof` checks above.\n return query as unknown as ConstrainedFlagQuery<T>;\n}\n\n// alias to the return value of useFlag, used to keep useSuspenseFlag consistent\ntype UseFlagReturn<T extends FlagValue> = ReturnType<typeof useFlag<T>>;\n\n/**\n * Equivalent to {@link useFlag} with `options: { suspend: true }`\n * @experimental Suspense is an experimental feature subject to change in future versions.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {NoSuspenseOptions} options for this evaluation\n * @returns { UseFlagReturn<T> } a queryable object containing useful information about the flag.\n */\nexport function useSuspenseFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: NoSuspenseOptions,\n): UseFlagReturn<T> {\n return useFlag(flagKey, defaultValue, { ...options, suspendUntilReady: true, suspendWhileReconciling: true });\n}\n\n/**\n * Evaluates a feature flag, returning a boolean.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagValue(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): boolean {\n return useBooleanFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<boolean>} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagDetails(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<boolean> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getBooleanDetails;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a string.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagValue<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): string {\n return useStringFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<string>} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagDetails<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<string> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getStringDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a number.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagValue<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): number {\n return useNumberFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<number>} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagDetails<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<number> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getNumberDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning an object.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagValue<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): T {\n return useObjectFlagDetails<T>(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {T} defaultValue the default value\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<T>} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagDetails<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getObjectDetails<T>;\n },\n options,\n );\n}\n\n// determines if a flag should be re-evaluated based on a list of changed flags\nfunction shouldEvaluateFlag(flagKey: string, flagsChanged?: string[]): boolean {\n return !!flagsChanged && flagsChanged.includes(flagKey);\n}\n\nfunction attachHandlersAndResolve<T extends FlagValue>(\n flagKey: string,\n defaultValue: T,\n resolver: (\n client: Client,\n ) => (flagKey: string, defaultValue: T, options?: FlagEvaluationOptions) => EvaluationDetails<T>,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n if (defaultedOptions.suspendWhileReconciling && status === ProviderStatus.RECONCILING) {\n suspendUntilReady(client);\n }\n\n const [evaluationDetails, setEvaluationDetails] = useState<EvaluationDetails<T>>(\n resolver(client).call(client, flagKey, defaultValue, options),\n );\n\n // Maintain a mutable reference to the evaluation details to have a up-to-date reference in the handlers.\n const evaluationDetailsRef = useRef<EvaluationDetails<T>>(evaluationDetails);\n useEffect(() => {\n evaluationDetailsRef.current = evaluationDetails;\n }, [evaluationDetails]);\n\n const updateEvaluationDetailsCallback = () => {\n const updatedEvaluationDetails = resolver(client).call(client, flagKey, defaultValue, options);\n\n /**\n * Avoid re-rendering if the value hasn't changed. We could expose a means\n * to define a custom comparison function if users require a more\n * sophisticated comparison in the future.\n */\n if (!isEqual(updatedEvaluationDetails.value, evaluationDetailsRef.current.value)) {\n setEvaluationDetails(updatedEvaluationDetails);\n }\n };\n\n const configurationChangeCallback: EventHandler<ClientProviderEvents.ConfigurationChanged> = (eventDetails) => {\n if (shouldEvaluateFlag(flagKey, eventDetails?.flagsChanged)) {\n updateEvaluationDetailsCallback();\n }\n };\n\n useEffect(() => {\n if (status === ProviderStatus.NOT_READY) {\n // update when the provider is ready\n client.addHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n }\n\n if (defaultedOptions.updateOnContextChanged) {\n // update when the context changes\n client.addHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n client.removeHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n useEffect(() => {\n if (defaultedOptions.updateOnConfigurationChanged) {\n // update when the provider configuration changes\n client.addHandler(ProviderEvents.ConfigurationChanged, configurationChangeCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.ConfigurationChanged, configurationChangeCallback);\n };\n }, []);\n\n return evaluationDetails;\n}\n", "import type { Client } from '@openfeature/web-sdk';\nimport React from 'react';\nimport type { NormalizedOptions, ReactFlagEvaluationOptions} from '../common';\nimport { normalizeOptions } from '../common';\n\n/**\n * The underlying React context.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const Context = React.createContext<{ client: Client; domain?: string; options: ReactFlagEvaluationOptions } | undefined>(undefined);\n\n/**\n * Get a normalized copy of the options used for this OpenFeatureProvider, see {@link normalizeOptions}.\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @returns {NormalizedOptions} normalized options the defaulted options, not defaulted or normalized.\n */\nexport function useProviderOptions(): NormalizedOptions {\n const { options } = React.useContext(Context) || {};\n return normalizeOptions(options);\n}\n", "import { type FlagValue } from '@openfeature/web-sdk';\n\n/**\n * Deeply compare two values to determine if they are equal.\n * Supports primitives and serializable objects.\n * @param {FlagValue} value First value to compare\n * @param {FlagValue} other Second value to compare\n * @returns {boolean} True if the values are equal\n */\nexport function isEqual(value: FlagValue, other: FlagValue): boolean {\n if (value === other) {\n return true;\n }\n\n if (typeof value !== typeof other) {\n return false;\n }\n\n if (typeof value === 'object' && value !== null && other !== null) {\n const valueKeys = Object.keys(value);\n const otherKeys = Object.keys(other);\n\n if (valueKeys.length !== otherKeys.length) {\n return false;\n }\n\n for (const key of valueKeys) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!isEqual((value as any)[key], (other as any)[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n", "import type { FlagEvaluationOptions } from '@openfeature/web-sdk';\n\nexport type ReactFlagEvaluationOptions = ({\n /**\n * Enable or disable all suspense functionality.\n * Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspend?: boolean;\n suspendUntilReady?: never;\n suspendWhileReconciling?: never;\n} | {\n /**\n * Suspend flag evaluations while the provider is not ready.\n * Set to false if you don't want to show suspense fallbacks until the provider is initialized.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendUntilReady?: boolean;\n /**\n * Suspend flag evaluations while the provider's context is being reconciled.\n * Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendWhileReconciling?: boolean;\n suspend?: never;\n}) & {\n /**\n * Update the component if the provider emits a ConfigurationChanged event.\n * Set to false to prevent components from re-rendering when flag value changes\n * are received by the associated provider.\n * Defaults to true.\n */\n updateOnConfigurationChanged?: boolean;\n /**\n * Update the component when the OpenFeature context changes.\n * Set to false to prevent components from re-rendering when attributes which\n * may be factors in flag evaluation change.\n * Defaults to true.\n */\n updateOnContextChanged?: boolean;\n} & FlagEvaluationOptions;\n\nexport type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>;\n\n/**\n * Default options.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const DEFAULT_OPTIONS: ReactFlagEvaluationOptions = {\n updateOnContextChanged: true,\n updateOnConfigurationChanged: true,\n suspendUntilReady: false,\n suspendWhileReconciling: false,\n};\n\n/**\n * Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`).\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @param {ReactFlagEvaluationOptions} options options to normalize\n * @returns {NormalizedOptions} normalized options\n */\nexport const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions = (options: ReactFlagEvaluationOptions = {}) => {\n const updateOnContextChanged = options.updateOnContextChanged;\n const updateOnConfigurationChanged = options.updateOnConfigurationChanged;\n\n // fall-back the suspense options to the catch-all `suspend` property \n const suspendUntilReady = 'suspendUntilReady' in options ? options.suspendUntilReady : options.suspend;\n const suspendWhileReconciling = 'suspendWhileReconciling' in options ? options.suspendWhileReconciling : options.suspend;\n\n return {\n // only return these if properly set (no undefined to allow overriding with spread)\n ...(typeof suspendUntilReady === 'boolean' && {suspendUntilReady}),\n ...(typeof suspendWhileReconciling === 'boolean' && {suspendWhileReconciling}),\n ...(typeof updateOnContextChanged === 'boolean' && {updateOnContextChanged}),\n ...(typeof updateOnConfigurationChanged === 'boolean' && {updateOnConfigurationChanged}),\n };\n};\n", "import type { Client} from '@openfeature/web-sdk';\nimport { ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Suspends until the client is ready to evaluate feature flags.\n * DO NOT EXPORT PUBLICLY\n * @param {Client} client OpenFeature client\n */\nexport function suspendUntilReady(client: Client): Promise<void> {\n let resolve: (value: unknown) => void;\n let reject: () => void;\n throw new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n client.addHandler(ProviderEvents.Ready, resolve);\n client.addHandler(ProviderEvents.Error, reject);\n }).finally(() => {\n client.removeHandler(ProviderEvents.Ready, resolve);\n client.removeHandler(ProviderEvents.Ready, reject);\n });\n}\n", "import React from 'react';\nimport { Context } from '../common';\nimport type { Client } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link Client} instance for this OpenFeatureProvider context.\n * Note that the provider to which this is bound is determined by the OpenFeatureProvider's domain.\n * @returns {Client} client for this scope\n */\nexport function useOpenFeatureClient(): Client {\n const { client } = React.useContext(Context) || {};\n\n if (!client) {\n throw new Error(\n 'No OpenFeature client available - components using OpenFeature must be wrapped with an <OpenFeatureProvider>. If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing',\n );\n }\n\n return client;\n}\n", "import { useEffect, useState } from 'react';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport type { ProviderStatus } from '@openfeature/web-sdk';\nimport { ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link ProviderStatus} for the OpenFeatureClient.\n * @returns {ProviderStatus} status of the client for this scope\n */\nexport function useOpenFeatureClientStatus(): ProviderStatus {\n const client = useOpenFeatureClient();\n const [status, setStatus] = useState(client.providerStatus);\n\n useEffect(() => {\n const updateStatus = () => setStatus(client.providerStatus);\n client.addHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.addHandler(ProviderEvents.ContextChanged, updateStatus);\n client.addHandler(ProviderEvents.Error, updateStatus);\n client.addHandler(ProviderEvents.Ready, updateStatus);\n client.addHandler(ProviderEvents.Stale, updateStatus);\n client.addHandler(ProviderEvents.Reconciling, updateStatus);\n return () => {\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.removeHandler(ProviderEvents.ContextChanged, updateStatus);\n client.removeHandler(ProviderEvents.Error, updateStatus);\n client.removeHandler(ProviderEvents.Ready, updateStatus);\n client.removeHandler(ProviderEvents.Stale, updateStatus);\n client.removeHandler(ProviderEvents.Reconciling, updateStatus);\n };\n }, [client]);\n\n return status;\n}\n", "import type {\n EvaluationDetails,\n FlagValue} from '@openfeature/web-sdk';\nimport {\n StandardResolutionReasons\n} from '@openfeature/web-sdk';\nimport type { FlagQuery } from '../query';\n\n\n// FlagQuery implementation, do not export\nexport class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {\n constructor(private _details: EvaluationDetails<T>) {}\n\n get details() {\n return this._details;\n }\n\n get value() {\n return this._details?.value;\n }\n\n get variant() {\n return this._details.variant;\n }\n\n get flagMetadata() {\n return this._details.flagMetadata;\n }\n\n get reason() {\n return this._details.reason;\n }\n\n get isError() {\n return !!this._details?.errorCode || this._details.reason == StandardResolutionReasons.ERROR;\n }\n\n get errorCode() {\n return this._details?.errorCode;\n }\n\n get errorMessage() {\n return this._details?.errorMessage;\n }\n\n get isAuthoritative() {\n return (\n !this.isError &&\n this._details.reason != StandardResolutionReasons.STALE &&\n this._details.reason != StandardResolutionReasons.DISABLED\n );\n }\n\n get type() {\n return typeof this._details.value;\n }\n}\n", "import type { Client} from '@openfeature/web-sdk';\nimport { OpenFeature } from '@openfeature/web-sdk';\nimport * as React from 'react';\nimport type { ReactFlagEvaluationOptions } from '../common';\nimport { Context } from '../common';\n\ntype ClientOrDomain =\n | {\n /**\n * An identifier which logically binds clients with providers\n * @see OpenFeature.setProvider() and overloads.\n */\n domain?: string;\n client?: never;\n }\n | {\n /**\n * OpenFeature client to use.\n */\n client?: Client;\n domain?: never;\n };\n\ntype ProviderProps = {\n children?: React.ReactNode;\n} & ClientOrDomain &\n ReactFlagEvaluationOptions;\n\n /**\n * Provides a scope for evaluating feature flags by binding a client to all child components.\n * @param {ProviderProps} properties props for the context provider\n * @returns {OpenFeatureProvider} context provider\n */\nexport function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps) {\n if (!client) {\n client = OpenFeature.getClient(domain);\n }\n\n return <Context.Provider value={{ client, options, domain }}>{children}</Context.Provider>;\n}\n", "import { ProviderStatus } from '@openfeature/web-sdk';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { useOpenFeatureClientStatus } from './use-open-feature-client-status';\nimport type { ReactFlagEvaluationOptions} from '../common';\nimport { DEFAULT_OPTIONS, useProviderOptions, normalizeOptions, suspendUntilReady } from '../common';\n\ntype Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;\n\n/**\n * Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.\n * Especially useful for React v16/17 \"Legacy Suspense\", in which siblings to suspending components are\n * initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).\n * @param {Options} options options for suspense\n * @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own\n */\nexport function useWhenProviderReady(options?: Options): boolean {\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n return status === ProviderStatus.READY;\n}\n", "import type {\n JsonValue,\n Provider} from '@openfeature/web-sdk';\nimport {\n InMemoryProvider,\n NOOP_PROVIDER,\n OpenFeature\n} from '@openfeature/web-sdk';\nimport React from 'react';\nimport type { NormalizedOptions } from '../common';\nimport { OpenFeatureProvider } from './provider';\n\ntype FlagValueMap = { [flagKey: string]: JsonValue };\ntype FlagConfig = ConstructorParameters<typeof InMemoryProvider>[0];\ntype TestProviderProps = Omit<React.ComponentProps<typeof OpenFeatureProvider>, 'client'> &\n (\n | {\n provider?: never;\n /**\n * Optional map of flagKeys to flagValues for this OpenFeatureTestProvider context.\n * If not supplied, all flag evaluations will default.\n */\n flagValueMap?: FlagValueMap;\n /**\n * Optional delay for the underlying test provider's readiness and reconciliation.\n * Defaults to 0.\n */\n delayMs?: number;\n }\n | {\n /**\n * An optional partial provider to pass for full control over the flag resolution for this OpenFeatureTestProvider context.\n * Any un-implemented methods or properties will no-op.\n */\n provider?: Partial<Provider>;\n flagValueMap?: never;\n delayMs?: never;\n }\n );\n\n const TEST_VARIANT = 'test-variant';\n const TEST_PROVIDER = 'test-provider';\n\n// internal provider which is basically the in-memory provider with a simpler config and some optional fake delays\nclass TestProvider extends InMemoryProvider {\n\n // initially make this undefined, we still set it if a delay is specified\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - For maximum compatibility with previous versions, we ignore a possible TS error here,\n // since \"initialize\" was previously defined in superclass.\n // We can safely remove this ts-ignore in a few versions\n initialize: Provider['initialize'] = undefined;\n\n // \"place-holder\" init function which we only assign if want a delay\n private delayedInitialize = async () => {\n await new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n };\n\n constructor(\n flagValueMap: FlagValueMap,\n private delay = 0,\n ) {\n // convert the simple flagValueMap into an in-memory config\n const flagConfig = Object.entries(flagValueMap).reduce((acc: FlagConfig, flag): FlagConfig => {\n return {\n ...acc,\n [flag[0]]: {\n variants: {\n [TEST_VARIANT]: flag[1],\n },\n defaultVariant: TEST_VARIANT,\n disabled: false,\n },\n };\n }, {});\n super(flagConfig);\n // only define and init if there's a non-zero delay specified\n this.initialize = this.delay ? this.delayedInitialize.bind(this) : undefined;\n }\n\n async onContextChange() {\n return new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n }\n}\n\n/**\n * A React Context provider based on the {@link InMemoryProvider}, specifically built for testing.\n * Use this for testing components that use flag evaluation hooks.\n * @param {TestProviderProps} testProviderOptions options for the OpenFeatureTestProvider\n * @returns {OpenFeatureProvider} OpenFeatureTestProvider\n */\nexport function OpenFeatureTestProvider(testProviderOptions: TestProviderProps) {\n const { flagValueMap, provider } = testProviderOptions;\n const effectiveProvider = (\n flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) || NOOP_PROVIDER\n ) as Provider;\n testProviderOptions.domain\n ? OpenFeature.setProvider(testProviderOptions.domain, effectiveProvider)\n : OpenFeature.setProvider(effectiveProvider);\n\n return (\n <OpenFeatureProvider {...(testProviderOptions as NormalizedOptions)} domain={testProviderOptions.domain}>\n {testProviderOptions.children}\n </OpenFeatureProvider>\n );\n}\n\n// mix in the no-op provider when the partial is passed\nfunction mixInNoop(provider: Partial<Provider> = {}) {\n // fill in any missing methods with no-ops\n for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(NOOP_PROVIDER)).filter(prop => prop !== 'constructor')) {\n const patchedProvider = provider as {[key: string]: keyof Provider};\n if (!Object.getPrototypeOf(patchedProvider)[prop] && !patchedProvider[prop]) {\n patchedProvider[prop] = Object.getPrototypeOf(NOOP_PROVIDER)[prop];\n }\n }\n // fill in the metadata if missing\n if (!provider.metadata || !provider.metadata.name) {\n (provider.metadata as unknown) = { name: TEST_PROVIDER };\n }\n return provider;\n}\n", "import { useCallback, useContext, useRef } from 'react';\nimport type { EvaluationContext } from '@openfeature/web-sdk';\nimport { OpenFeature } from '@openfeature/web-sdk';\nimport { Context } from '../common';\n\nexport type ContextMutationOptions = {\n /**\n * Mutate the default context instead of the domain scoped context applied at the `<OpenFeatureProvider/>`.\n * Note, if the `<OpenFeatureProvider/>` has no domain specified, the default is used.\n * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#manage-evaluation-context-for-domains|documentation} for more information.\n * @default false\n */\n defaultContext?: boolean;\n};\n\nexport type ContextMutation = {\n /**\n * Context-aware function to set the desired context (see: {@link ContextMutationOptions} for details).\n * There's generally no need to await the result of this function; flag evaluation hooks will re-render when the context is updated.\n * This promise never rejects.\n * @param updatedContext\n * @returns Promise for awaiting the context update\n */\n setContext: (updatedContext: EvaluationContext) => Promise<void>;\n};\n\n/**\n * Get context-aware tracking function(s) for mutating the evaluation context associated with this domain, or the default context if `defaultContext: true`.\n * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#targeting-and-context|documentation} for more information.\n * @param {ContextMutationOptions} options options for the generated function\n * @returns {ContextMutation} context-aware function(s) to mutate evaluation context\n */\nexport function useContextMutator(options: ContextMutationOptions = { defaultContext: false }): ContextMutation {\n const { domain } = useContext(Context) || {};\n const previousContext = useRef<null | EvaluationContext>(null);\n\n const setContext = useCallback(async (updatedContext: EvaluationContext) => {\n if (previousContext.current !== updatedContext) {\n if (!domain || options?.defaultContext) {\n OpenFeature.setContext(updatedContext);\n } else {\n OpenFeature.setContext(domain, updatedContext);\n }\n previousContext.current = updatedContext;\n }\n }, [domain]);\n\n return {\n setContext,\n };\n}\n", "import type { Tracking, TrackingEventDetails } from '@openfeature/web-sdk';\nimport { useCallback } from 'react';\nimport { useOpenFeatureClient } from '../provider';\n\nexport type Track = {\n /**\n * Context-aware tracking function for the parent `<OpenFeatureProvider/>`.\n * Track a user action or application state, usually representing a business objective or outcome.\n * @param trackingEventName an identifier for the event\n * @param trackingEventDetails the details of the tracking event\n */\n track: Tracking['track'];\n};\n\n/**\n * Get a context-aware tracking function.\n * @returns {Track} context-aware tracking\n */\nexport function useTrack(): Track {\n const client = useOpenFeatureClient();\n\n const track = useCallback((trackingEventName: string, trackingEventDetails?: TrackingEventDetails) => {\n client.track(trackingEventName, trackingEventDetails);\n }, []);\n\n return {\n track,\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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A,IAAAC,gBAAgD;AAEhD,IAAAC,kBAA4B;AA8BrB,SAAS,kBAAkB,UAAkC,EAAE,gBAAgB,MAAM,GAAoB;AAC5G,QAAM,EAAE,OAAO,QAAI,0BAAW,OAAO,KAAK,CAAC;AAC3C,QAAM,sBAAkB,sBAAiC,IAAI;AAE7D,QAAM,iBAAa,2BAAY,CAAO,mBAAsC;AACxE,QAAI,gBAAgB,YAAY,gBAAgB;AAC5C,UAAI,CAAC,WAAU,mCAAS,iBAAgB;AACpC,oCAAY,WAAW,cAAc;AAAA,MACzC,OAAO;AACH,oCAAY,WAAW,QAAQ,cAAc;AAAA,MACjD;AACA,sBAAgB,UAAU;AAAA,IAC9B;AAAA,EACJ,IAAG,CAAC,MAAM,CAAC;AAEX,SAAO;AAAA,IACH;AAAA,EACJ;AACJ;;;ACjDA,IAAAC,gBAA4B;AAiBrB,SAAS,WAAkB;AAChC,QAAM,SAAS,qBAAqB;AAEpC,QAAM,YAAQ,2BAAY,CAAC,mBAA2B,yBAAgD;AACpG,WAAO,MAAM,mBAAmB,oBAAoB;AAAA,EACtD,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AbtBA,wBAAc,iCANd;",
|
|
6
|
+
"names": ["import_web_sdk", "import_react", "React", "suspendUntilReady", "import_react", "React", "import_react", "import_web_sdk", "import_web_sdk", "import_web_sdk", "React", "import_web_sdk", "import_web_sdk", "import_react", "React", "prop", "import_react", "import_web_sdk", "import_react"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -53,10 +53,42 @@ var __async = (__this, __arguments, generator) => {
|
|
|
53
53
|
// src/evaluation/use-feature-flag.ts
|
|
54
54
|
import {
|
|
55
55
|
ProviderEvents as ProviderEvents3,
|
|
56
|
-
ProviderStatus
|
|
56
|
+
ProviderStatus
|
|
57
57
|
} from "@openfeature/web-sdk";
|
|
58
58
|
import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
59
59
|
|
|
60
|
+
// src/common/context.ts
|
|
61
|
+
import React from "react";
|
|
62
|
+
var Context = React.createContext(void 0);
|
|
63
|
+
function useProviderOptions() {
|
|
64
|
+
const { options } = React.useContext(Context) || {};
|
|
65
|
+
return normalizeOptions(options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/common/is-equal.ts
|
|
69
|
+
function isEqual(value, other) {
|
|
70
|
+
if (value === other) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (typeof value !== typeof other) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === "object" && value !== null && other !== null) {
|
|
77
|
+
const valueKeys = Object.keys(value);
|
|
78
|
+
const otherKeys = Object.keys(other);
|
|
79
|
+
if (valueKeys.length !== otherKeys.length) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
for (const key of valueKeys) {
|
|
83
|
+
if (!isEqual(value[key], other[key])) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
60
92
|
// src/common/options.ts
|
|
61
93
|
var DEFAULT_OPTIONS = {
|
|
62
94
|
updateOnContextChanged: true,
|
|
@@ -88,14 +120,6 @@ function suspendUntilReady(client) {
|
|
|
88
120
|
});
|
|
89
121
|
}
|
|
90
122
|
|
|
91
|
-
// src/provider/context.ts
|
|
92
|
-
import React from "react";
|
|
93
|
-
var Context = React.createContext(void 0);
|
|
94
|
-
function useProviderOptions() {
|
|
95
|
-
const { options } = React.useContext(Context) || {};
|
|
96
|
-
return normalizeOptions(options);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
123
|
// src/provider/use-open-feature-client.ts
|
|
100
124
|
import React2 from "react";
|
|
101
125
|
function useOpenFeatureClient() {
|
|
@@ -178,30 +202,6 @@ var HookFlagQuery = class {
|
|
|
178
202
|
}
|
|
179
203
|
};
|
|
180
204
|
|
|
181
|
-
// src/common/is-equal.ts
|
|
182
|
-
function isEqual(value, other) {
|
|
183
|
-
if (value === other) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
if (typeof value !== typeof other) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
if (typeof value === "object" && value !== null && other !== null) {
|
|
190
|
-
const valueKeys = Object.keys(value);
|
|
191
|
-
const otherKeys = Object.keys(other);
|
|
192
|
-
if (valueKeys.length !== otherKeys.length) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
for (const key of valueKeys) {
|
|
196
|
-
if (!isEqual(value[key], other[key])) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
205
|
// src/evaluation/use-feature-flag.ts
|
|
206
206
|
function useFlag(flagKey, defaultValue, options) {
|
|
207
207
|
const query = typeof defaultValue === "boolean" ? new HookFlagQuery(useBooleanFlagDetails(flagKey, defaultValue, options)) : typeof defaultValue === "number" ? new HookFlagQuery(useNumberFlagDetails(flagKey, defaultValue, options)) : typeof defaultValue === "string" ? new HookFlagQuery(useStringFlagDetails(flagKey, defaultValue, options)) : new HookFlagQuery(useObjectFlagDetails(flagKey, defaultValue, options));
|
|
@@ -262,14 +262,17 @@ function useObjectFlagDetails(flagKey, defaultValue, options) {
|
|
|
262
262
|
options
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
|
+
function shouldEvaluateFlag(flagKey, flagsChanged) {
|
|
266
|
+
return !!flagsChanged && flagsChanged.includes(flagKey);
|
|
267
|
+
}
|
|
265
268
|
function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
266
269
|
const defaultedOptions = __spreadValues(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), useProviderOptions()), normalizeOptions(options));
|
|
267
270
|
const client = useOpenFeatureClient();
|
|
268
271
|
const status = useOpenFeatureClientStatus();
|
|
269
|
-
if (defaultedOptions.suspendUntilReady && status ===
|
|
272
|
+
if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {
|
|
270
273
|
suspendUntilReady(client);
|
|
271
274
|
}
|
|
272
|
-
if (defaultedOptions.suspendWhileReconciling && status ===
|
|
275
|
+
if (defaultedOptions.suspendWhileReconciling && status === ProviderStatus.RECONCILING) {
|
|
273
276
|
suspendUntilReady(client);
|
|
274
277
|
}
|
|
275
278
|
const [evaluationDetails, setEvaluationDetails] = useState2(
|
|
@@ -285,8 +288,13 @@ function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
|
285
288
|
setEvaluationDetails(updatedEvaluationDetails);
|
|
286
289
|
}
|
|
287
290
|
};
|
|
291
|
+
const configurationChangeCallback = (eventDetails) => {
|
|
292
|
+
if (shouldEvaluateFlag(flagKey, eventDetails == null ? void 0 : eventDetails.flagsChanged)) {
|
|
293
|
+
updateEvaluationDetailsCallback();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
288
296
|
useEffect2(() => {
|
|
289
|
-
if (status ===
|
|
297
|
+
if (status === ProviderStatus.NOT_READY) {
|
|
290
298
|
client.addHandler(ProviderEvents3.Ready, updateEvaluationDetailsCallback);
|
|
291
299
|
}
|
|
292
300
|
if (defaultedOptions.updateOnContextChanged) {
|
|
@@ -299,10 +307,10 @@ function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
|
299
307
|
}, []);
|
|
300
308
|
useEffect2(() => {
|
|
301
309
|
if (defaultedOptions.updateOnConfigurationChanged) {
|
|
302
|
-
client.addHandler(ProviderEvents3.ConfigurationChanged,
|
|
310
|
+
client.addHandler(ProviderEvents3.ConfigurationChanged, configurationChangeCallback);
|
|
303
311
|
}
|
|
304
312
|
return () => {
|
|
305
|
-
client.removeHandler(ProviderEvents3.ConfigurationChanged,
|
|
313
|
+
client.removeHandler(ProviderEvents3.ConfigurationChanged, configurationChangeCallback);
|
|
306
314
|
};
|
|
307
315
|
}, []);
|
|
308
316
|
return evaluationDetails;
|
|
@@ -316,19 +324,19 @@ function OpenFeatureProvider(_a) {
|
|
|
316
324
|
if (!client) {
|
|
317
325
|
client = OpenFeature.getClient(domain);
|
|
318
326
|
}
|
|
319
|
-
return /* @__PURE__ */ React3.createElement(Context.Provider, { value: { client, options } }, children);
|
|
327
|
+
return /* @__PURE__ */ React3.createElement(Context.Provider, { value: { client, options, domain } }, children);
|
|
320
328
|
}
|
|
321
329
|
|
|
322
330
|
// src/provider/use-when-provider-ready.ts
|
|
323
|
-
import { ProviderStatus as
|
|
331
|
+
import { ProviderStatus as ProviderStatus2 } from "@openfeature/web-sdk";
|
|
324
332
|
function useWhenProviderReady(options) {
|
|
325
333
|
const client = useOpenFeatureClient();
|
|
326
334
|
const status = useOpenFeatureClientStatus();
|
|
327
335
|
const defaultedOptions = __spreadValues(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), useProviderOptions()), normalizeOptions(options));
|
|
328
|
-
if (defaultedOptions.suspendUntilReady && status ===
|
|
336
|
+
if (defaultedOptions.suspendUntilReady && status === ProviderStatus2.NOT_READY) {
|
|
329
337
|
suspendUntilReady(client);
|
|
330
338
|
}
|
|
331
|
-
return status ===
|
|
339
|
+
return status === ProviderStatus2.READY;
|
|
332
340
|
}
|
|
333
341
|
|
|
334
342
|
// src/provider/test-provider.tsx
|
|
@@ -392,6 +400,39 @@ function mixInNoop(provider = {}) {
|
|
|
392
400
|
return provider;
|
|
393
401
|
}
|
|
394
402
|
|
|
403
|
+
// src/context/use-context-mutator.ts
|
|
404
|
+
import { useCallback, useContext, useRef as useRef2 } from "react";
|
|
405
|
+
import { OpenFeature as OpenFeature3 } from "@openfeature/web-sdk";
|
|
406
|
+
function useContextMutator(options = { defaultContext: false }) {
|
|
407
|
+
const { domain } = useContext(Context) || {};
|
|
408
|
+
const previousContext = useRef2(null);
|
|
409
|
+
const setContext = useCallback((updatedContext) => __async(this, null, function* () {
|
|
410
|
+
if (previousContext.current !== updatedContext) {
|
|
411
|
+
if (!domain || (options == null ? void 0 : options.defaultContext)) {
|
|
412
|
+
OpenFeature3.setContext(updatedContext);
|
|
413
|
+
} else {
|
|
414
|
+
OpenFeature3.setContext(domain, updatedContext);
|
|
415
|
+
}
|
|
416
|
+
previousContext.current = updatedContext;
|
|
417
|
+
}
|
|
418
|
+
}), [domain]);
|
|
419
|
+
return {
|
|
420
|
+
setContext
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/tracking/use-track.ts
|
|
425
|
+
import { useCallback as useCallback2 } from "react";
|
|
426
|
+
function useTrack() {
|
|
427
|
+
const client = useOpenFeatureClient();
|
|
428
|
+
const track = useCallback2((trackingEventName, trackingEventDetails) => {
|
|
429
|
+
client.track(trackingEventName, trackingEventDetails);
|
|
430
|
+
}, []);
|
|
431
|
+
return {
|
|
432
|
+
track
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
395
436
|
// src/index.ts
|
|
396
437
|
export * from "@openfeature/web-sdk";
|
|
397
438
|
export {
|
|
@@ -399,6 +440,7 @@ export {
|
|
|
399
440
|
OpenFeatureTestProvider,
|
|
400
441
|
useBooleanFlagDetails,
|
|
401
442
|
useBooleanFlagValue,
|
|
443
|
+
useContextMutator,
|
|
402
444
|
useFlag,
|
|
403
445
|
useNumberFlagDetails,
|
|
404
446
|
useNumberFlagValue,
|
|
@@ -408,6 +450,7 @@ export {
|
|
|
408
450
|
useStringFlagDetails,
|
|
409
451
|
useStringFlagValue,
|
|
410
452
|
useSuspenseFlag,
|
|
453
|
+
useTrack,
|
|
411
454
|
useWhenProviderReady
|
|
412
455
|
};
|
|
413
456
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/evaluation/use-feature-flag.ts", "../../src/common/
|
|
4
|
-
"sourcesContent": ["import {\n Client,\n EvaluationDetails,\n FlagEvaluationOptions,\n FlagValue,\n JsonValue,\n ProviderEvents,\n ProviderStatus,\n} from '@openfeature/web-sdk';\nimport { useEffect, useRef, useState } from 'react';\nimport { DEFAULT_OPTIONS, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\nimport { suspendUntilReady } from '../common/suspense';\nimport { useProviderOptions } from '../provider/context';\nimport { useOpenFeatureClient } from '../provider/use-open-feature-client';\nimport { useOpenFeatureClientStatus } from '../provider/use-open-feature-client-status';\nimport { FlagQuery } from '../query';\nimport { HookFlagQuery } from './hook-flag-query';\nimport { isEqual } from '../common/is-equal';\n\n// This type is a bit wild-looking, but I think we need it.\n// We have to use the conditional, because otherwise useFlag('key', false) would return false, not boolean (too constrained).\n// We have a duplicate for the hook return below, this one is just used for casting because the name isn't as clear\ntype ConstrainedFlagQuery<T> = FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n>;\n\n// suspense options removed for the useSuspenseFlag hooks\ntype NoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>;\n\n/**\n * Evaluates a feature flag generically, returning an react-flavored queryable object.\n * The resolver method to use is based on the type of the defaultValue.\n * For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails} and equivalents.\n * By default, components will re-render when the flag value changes.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {ReactFlagEvaluationOptions} options for this evaluation\n * @returns { FlagQuery } a queryable object containing useful information about the flag.\n */\nexport function useFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n> {\n // use the default value to determine the resolver to call\n const query =\n typeof defaultValue === 'boolean'\n ? new HookFlagQuery<boolean>(useBooleanFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'number'\n ? new HookFlagQuery<number>(useNumberFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'string'\n ? new HookFlagQuery<string>(useStringFlagDetails(flagKey, defaultValue, options))\n : new HookFlagQuery<JsonValue>(useObjectFlagDetails(flagKey, defaultValue, options));\n // TS sees this as HookFlagQuery<JsonValue>, because the compiler isn't aware of the `typeof` checks above.\n return query as unknown as ConstrainedFlagQuery<T>;\n}\n\n// alias to the return value of useFlag, used to keep useSuspenseFlag consistent\ntype UseFlagReturn<T extends FlagValue> = ReturnType<typeof useFlag<T>>;\n\n/**\n * Equivalent to {@link useFlag} with `options: { suspend: true }`\n * @experimental Suspense is an experimental feature subject to change in future versions.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {NoSuspenseOptions} options for this evaluation\n * @returns { UseFlagReturn<T> } a queryable object containing useful information about the flag.\n */\nexport function useSuspenseFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: NoSuspenseOptions,\n): UseFlagReturn<T> {\n return useFlag(flagKey, defaultValue, { ...options, suspendUntilReady: true, suspendWhileReconciling: true });\n}\n\n/**\n * Evaluates a feature flag, returning a boolean.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagValue(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): boolean {\n return useBooleanFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<boolean>} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagDetails(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<boolean> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getBooleanDetails;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a string.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagValue<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): string {\n return useStringFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<string>} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagDetails<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<string> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getStringDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a number.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagValue<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): number {\n return useNumberFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<number>} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagDetails<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<number> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getNumberDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning an object.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagValue<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): T {\n return useObjectFlagDetails<T>(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {T} defaultValue the default value\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<T>} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagDetails<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getObjectDetails<T>;\n },\n options,\n );\n}\n\nfunction attachHandlersAndResolve<T extends FlagValue>(\n flagKey: string,\n defaultValue: T,\n resolver: (\n client: Client,\n ) => (flagKey: string, defaultValue: T, options?: FlagEvaluationOptions) => EvaluationDetails<T>,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n if (defaultedOptions.suspendWhileReconciling && status === ProviderStatus.RECONCILING) {\n suspendUntilReady(client);\n }\n\n const [evaluationDetails, setEvaluationDetails] = useState<EvaluationDetails<T>>(\n resolver(client).call(client, flagKey, defaultValue, options),\n );\n\n // Maintain a mutable reference to the evaluation details to have a up-to-date reference in the handlers.\n const evaluationDetailsRef = useRef<EvaluationDetails<T>>(evaluationDetails);\n useEffect(() => {\n evaluationDetailsRef.current = evaluationDetails;\n }, [evaluationDetails]);\n\n const updateEvaluationDetailsCallback = () => {\n const updatedEvaluationDetails = resolver(client).call(client, flagKey, defaultValue, options);\n\n /**\n * Avoid re-rendering if the value hasn't changed. We could expose a means\n * to define a custom comparison function if users require a more\n * sophisticated comparison in the future.\n */\n if (!isEqual(updatedEvaluationDetails.value, evaluationDetailsRef.current.value)) {\n setEvaluationDetails(updatedEvaluationDetails);\n }\n };\n\n useEffect(() => {\n if (status === ProviderStatus.NOT_READY) {\n // update when the provider is ready\n client.addHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n }\n\n if (defaultedOptions.updateOnContextChanged) {\n // update when the context changes\n client.addHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n client.removeHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n useEffect(() => {\n if (defaultedOptions.updateOnConfigurationChanged) {\n // update when the provider configuration changes\n client.addHandler(ProviderEvents.ConfigurationChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n return evaluationDetails;\n}\n", "import { FlagEvaluationOptions } from '@openfeature/web-sdk';\n\nexport type ReactFlagEvaluationOptions = ({\n /**\n * Enable or disable all suspense functionality.\n * Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspend?: boolean;\n suspendUntilReady?: never;\n suspendWhileReconciling?: never;\n} | {\n /**\n * Suspend flag evaluations while the provider is not ready.\n * Set to false if you don't want to show suspense fallbacks until the provider is initialized.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendUntilReady?: boolean;\n /**\n * Suspend flag evaluations while the provider's context is being reconciled.\n * Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendWhileReconciling?: boolean;\n suspend?: never;\n}) & {\n /**\n * Update the component if the provider emits a ConfigurationChanged event.\n * Set to false to prevent components from re-rendering when flag value changes\n * are received by the associated provider.\n * Defaults to true.\n */\n updateOnConfigurationChanged?: boolean;\n /**\n * Update the component when the OpenFeature context changes.\n * Set to false to prevent components from re-rendering when attributes which\n * may be factors in flag evaluation change.\n * Defaults to true.\n */\n updateOnContextChanged?: boolean;\n} & FlagEvaluationOptions;\n\nexport type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>;\n\n/**\n * Default options.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const DEFAULT_OPTIONS: ReactFlagEvaluationOptions = {\n updateOnContextChanged: true,\n updateOnConfigurationChanged: true,\n suspendUntilReady: false,\n suspendWhileReconciling: false,\n};\n\n/**\n * Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`).\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @param {ReactFlagEvaluationOptions} options options to normalize\n * @returns {NormalizedOptions} normalized options\n */\nexport const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions = (options: ReactFlagEvaluationOptions = {}) => {\n const updateOnContextChanged = options.updateOnContextChanged;\n const updateOnConfigurationChanged = options.updateOnConfigurationChanged;\n\n // fall-back the suspense options to the catch-all `suspend` property \n const suspendUntilReady = 'suspendUntilReady' in options ? options.suspendUntilReady : options.suspend;\n const suspendWhileReconciling = 'suspendWhileReconciling' in options ? options.suspendWhileReconciling : options.suspend;\n\n return {\n // only return these if properly set (no undefined to allow overriding with spread)\n ...(typeof suspendUntilReady === 'boolean' && {suspendUntilReady}),\n ...(typeof suspendWhileReconciling === 'boolean' && {suspendWhileReconciling}),\n ...(typeof updateOnContextChanged === 'boolean' && {updateOnContextChanged}),\n ...(typeof updateOnConfigurationChanged === 'boolean' && {updateOnConfigurationChanged}),\n };\n};\n", "import { Client, ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Suspends until the client is ready to evaluate feature flags.\n * DO NOT EXPORT PUBLICLY\n * @param {Client} client OpenFeature client\n */\nexport function suspendUntilReady(client: Client): Promise<void> {\n let resolve: (value: unknown) => void;\n let reject: () => void;\n throw new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n client.addHandler(ProviderEvents.Ready, resolve);\n client.addHandler(ProviderEvents.Error, reject);\n }).finally(() => {\n client.removeHandler(ProviderEvents.Ready, resolve);\n client.removeHandler(ProviderEvents.Ready, reject);\n });\n}\n", "import { Client } from '@openfeature/web-sdk';\nimport React from 'react';\nimport { NormalizedOptions, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\n\n/**\n * The underlying React context.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const Context = React.createContext<{ client: Client; options: ReactFlagEvaluationOptions } | undefined>(undefined);\n\n/**\n * Get a normalized copy of the options used for this OpenFeatureProvider, see {@link normalizeOptions}.\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @returns {NormalizedOptions} normalized options the defaulted options, not defaulted or normalized.\n */\nexport function useProviderOptions(): NormalizedOptions {\n const { options } = React.useContext(Context) || {};\n return normalizeOptions(options);\n}\n", "import React from 'react';\nimport { Context } from './context';\nimport { Client } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link Client} instance for this OpenFeatureProvider context.\n * Note that the provider to which this is bound is determined by the OpenFeatureProvider's domain.\n * @returns {Client} client for this scope\n */\nexport function useOpenFeatureClient(): Client {\n const { client } = React.useContext(Context) || {};\n\n if (!client) {\n throw new Error(\n 'No OpenFeature client available - components using OpenFeature must be wrapped with an <OpenFeatureProvider>. If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing',\n );\n }\n\n return client;\n}\n", "import { useEffect, useState } from 'react';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { ProviderEvents, ProviderStatus } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link ProviderStatus} for the OpenFeatureClient.\n * @returns {ProviderStatus} status of the client for this scope\n */\nexport function useOpenFeatureClientStatus(): ProviderStatus {\n const client = useOpenFeatureClient();\n const [status, setStatus] = useState(client.providerStatus);\n\n useEffect(() => {\n const updateStatus = () => setStatus(client.providerStatus);\n client.addHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.addHandler(ProviderEvents.ContextChanged, updateStatus);\n client.addHandler(ProviderEvents.Error, updateStatus);\n client.addHandler(ProviderEvents.Ready, updateStatus);\n client.addHandler(ProviderEvents.Stale, updateStatus);\n client.addHandler(ProviderEvents.Reconciling, updateStatus);\n return () => {\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.removeHandler(ProviderEvents.ContextChanged, updateStatus);\n client.removeHandler(ProviderEvents.Error, updateStatus);\n client.removeHandler(ProviderEvents.Ready, updateStatus);\n client.removeHandler(ProviderEvents.Stale, updateStatus);\n client.removeHandler(ProviderEvents.Reconciling, updateStatus);\n };\n }, [client]);\n\n return status;\n}\n", "import {\n EvaluationDetails,\n FlagValue,\n StandardResolutionReasons\n} from '@openfeature/web-sdk';\nimport { FlagQuery } from '../query';\n\n\n// FlagQuery implementation, do not export\nexport class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {\n constructor(private _details: EvaluationDetails<T>) {}\n\n get details() {\n return this._details;\n }\n\n get value() {\n return this._details?.value;\n }\n\n get variant() {\n return this._details.variant;\n }\n\n get flagMetadata() {\n return this._details.flagMetadata;\n }\n\n get reason() {\n return this._details.reason;\n }\n\n get isError() {\n return !!this._details?.errorCode || this._details.reason == StandardResolutionReasons.ERROR;\n }\n\n get errorCode() {\n return this._details?.errorCode;\n }\n\n get errorMessage() {\n return this._details?.errorMessage;\n }\n\n get isAuthoritative() {\n return (\n !this.isError &&\n this._details.reason != StandardResolutionReasons.STALE &&\n this._details.reason != StandardResolutionReasons.DISABLED\n );\n }\n\n get type() {\n return typeof this._details.value;\n }\n}\n", "import { type FlagValue } from '@openfeature/web-sdk';\n\n/**\n * Deeply compare two values to determine if they are equal.\n * Supports primitives and serializable objects.\n * @param {FlagValue} value First value to compare\n * @param {FlagValue} other Second value to compare\n * @returns {boolean} True if the values are equal\n */\nexport function isEqual(value: FlagValue, other: FlagValue): boolean {\n if (value === other) {\n return true;\n }\n\n if (typeof value !== typeof other) {\n return false;\n }\n\n if (typeof value === 'object' && value !== null && other !== null) {\n const valueKeys = Object.keys(value);\n const otherKeys = Object.keys(other);\n\n if (valueKeys.length !== otherKeys.length) {\n return false;\n }\n\n for (const key of valueKeys) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!isEqual((value as any)[key], (other as any)[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n", "import { Client, OpenFeature } from '@openfeature/web-sdk';\nimport * as React from 'react';\nimport { ReactFlagEvaluationOptions } from '../common/options';\nimport { Context } from './context';\n\ntype ClientOrDomain =\n | {\n /**\n * An identifier which logically binds clients with providers\n * @see OpenFeature.setProvider() and overloads.\n */\n domain?: string;\n client?: never;\n }\n | {\n /**\n * OpenFeature client to use.\n */\n client?: Client;\n domain?: never;\n };\n\ntype ProviderProps = {\n children?: React.ReactNode;\n} & ClientOrDomain &\n ReactFlagEvaluationOptions;\n\n /**\n * Provides a scope for evaluating feature flags by binding a client to all child components.\n * @param {ProviderProps} properties props for the context provider\n * @returns {OpenFeatureProvider} context provider\n */\nexport function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps) {\n if (!client) {\n client = OpenFeature.getClient(domain);\n }\n\n return <Context.Provider value={{ client, options }}>{children}</Context.Provider>;\n}\n", "import { ProviderStatus } from '@openfeature/web-sdk';\nimport { DEFAULT_OPTIONS, ReactFlagEvaluationOptions, normalizeOptions } from '../common/options';\nimport { useProviderOptions } from './context';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { useOpenFeatureClientStatus } from './use-open-feature-client-status';\nimport { suspendUntilReady } from '../common/suspense';\n\ntype Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;\n\n/**\n * Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.\n * Especially useful for React v16/17 \"Legacy Suspense\", in which siblings to suspending components are\n * initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).\n * @param {Options} options options for suspense\n * @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own\n */\nexport function useWhenProviderReady(options?: Options): boolean {\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n return status === ProviderStatus.READY;\n}\n", "import {\n InMemoryProvider,\n JsonValue,\n NOOP_PROVIDER,\n OpenFeature,\n Provider,\n} from '@openfeature/web-sdk';\nimport React from 'react';\nimport { NormalizedOptions } from '../common/options';\nimport { OpenFeatureProvider } from './provider';\n\ntype FlagValueMap = { [flagKey: string]: JsonValue };\ntype FlagConfig = ConstructorParameters<typeof InMemoryProvider>[0];\ntype TestProviderProps = Omit<React.ComponentProps<typeof OpenFeatureProvider>, 'client'> &\n (\n | {\n provider?: never;\n /**\n * Optional map of flagKeys to flagValues for this OpenFeatureTestProvider context.\n * If not supplied, all flag evaluations will default.\n */\n flagValueMap?: FlagValueMap;\n /**\n * Optional delay for the underlying test provider's readiness and reconciliation.\n * Defaults to 0.\n */\n delayMs?: number;\n }\n | {\n /**\n * An optional partial provider to pass for full control over the flag resolution for this OpenFeatureTestProvider context.\n * Any un-implemented methods or properties will no-op.\n */\n provider?: Partial<Provider>;\n flagValueMap?: never;\n delayMs?: never;\n }\n );\n\n const TEST_VARIANT = 'test-variant';\n const TEST_PROVIDER = 'test-provider';\n\n// internal provider which is basically the in-memory provider with a simpler config and some optional fake delays\nclass TestProvider extends InMemoryProvider {\n\n // initially make this undefined, we still set it if a delay is specified\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - For maximum compatibility with previous versions, we ignore a possible TS error here,\n // since \"initialize\" was previously defined in superclass.\n // We can safely remove this ts-ignore in a few versions\n initialize: Provider['initialize'] = undefined;\n\n // \"place-holder\" init function which we only assign if want a delay\n private delayedInitialize = async () => {\n await new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n };\n\n constructor(\n flagValueMap: FlagValueMap,\n private delay = 0,\n ) {\n // convert the simple flagValueMap into an in-memory config\n const flagConfig = Object.entries(flagValueMap).reduce((acc: FlagConfig, flag): FlagConfig => {\n return {\n ...acc,\n [flag[0]]: {\n variants: {\n [TEST_VARIANT]: flag[1],\n },\n defaultVariant: TEST_VARIANT,\n disabled: false,\n },\n };\n }, {});\n super(flagConfig);\n // only define and init if there's a non-zero delay specified\n this.initialize = this.delay ? this.delayedInitialize.bind(this) : undefined;\n }\n\n async onContextChange() {\n return new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n }\n}\n\n/**\n * A React Context provider based on the {@link InMemoryProvider}, specifically built for testing.\n * Use this for testing components that use flag evaluation hooks.\n * @param {TestProviderProps} testProviderOptions options for the OpenFeatureTestProvider\n * @returns {OpenFeatureProvider} OpenFeatureTestProvider\n */\nexport function OpenFeatureTestProvider(testProviderOptions: TestProviderProps) {\n const { flagValueMap, provider } = testProviderOptions;\n const effectiveProvider = (\n flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) || NOOP_PROVIDER\n ) as Provider;\n testProviderOptions.domain\n ? OpenFeature.setProvider(testProviderOptions.domain, effectiveProvider)\n : OpenFeature.setProvider(effectiveProvider);\n\n return (\n <OpenFeatureProvider {...(testProviderOptions as NormalizedOptions)} domain={testProviderOptions.domain}>\n {testProviderOptions.children}\n </OpenFeatureProvider>\n );\n}\n\n// mix in the no-op provider when the partial is passed\nfunction mixInNoop(provider: Partial<Provider> = {}) {\n // fill in any missing methods with no-ops\n for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(NOOP_PROVIDER)).filter(prop => prop !== 'constructor')) {\n const patchedProvider = provider as {[key: string]: keyof Provider};\n if (!Object.getPrototypeOf(patchedProvider)[prop] && !patchedProvider[prop]) {\n patchedProvider[prop] = Object.getPrototypeOf(NOOP_PROVIDER)[prop];\n }\n }\n // fill in the metadata if missing\n if (!provider.metadata || !provider.metadata.name) {\n (provider.metadata as unknown) = { name: TEST_PROVIDER };\n }\n return provider;\n}", "export * from './evaluation';\nexport * from './query';\nexport * from './provider';\n// re-export the web-sdk so consumers can access that API from the react-sdk\nexport * from '@openfeature/web-sdk';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
6
|
-
"names": ["ProviderEvents", "
|
|
3
|
+
"sources": ["../../src/evaluation/use-feature-flag.ts", "../../src/common/context.ts", "../../src/common/is-equal.ts", "../../src/common/options.ts", "../../src/common/suspense.ts", "../../src/provider/use-open-feature-client.ts", "../../src/provider/use-open-feature-client-status.ts", "../../src/evaluation/hook-flag-query.ts", "../../src/provider/provider.tsx", "../../src/provider/use-when-provider-ready.ts", "../../src/provider/test-provider.tsx", "../../src/context/use-context-mutator.ts", "../../src/tracking/use-track.ts", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n Client,\n ClientProviderEvents,\n EvaluationDetails,\n EventHandler,\n FlagEvaluationOptions,\n FlagValue,\n JsonValue} from '@openfeature/web-sdk';\nimport {\n ProviderEvents,\n ProviderStatus,\n} from '@openfeature/web-sdk';\nimport { useEffect, useRef, useState } from 'react';\nimport type { ReactFlagEvaluationOptions} from '../common';\nimport { DEFAULT_OPTIONS, isEqual, normalizeOptions, suspendUntilReady, useProviderOptions } from '../common';\nimport { useOpenFeatureClient } from '../provider/use-open-feature-client';\nimport { useOpenFeatureClientStatus } from '../provider/use-open-feature-client-status';\nimport type { FlagQuery } from '../query';\nimport { HookFlagQuery } from './hook-flag-query';\n\n// This type is a bit wild-looking, but I think we need it.\n// We have to use the conditional, because otherwise useFlag('key', false) would return false, not boolean (too constrained).\n// We have a duplicate for the hook return below, this one is just used for casting because the name isn't as clear\ntype ConstrainedFlagQuery<T> = FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n>;\n\n// suspense options removed for the useSuspenseFlag hooks\ntype NoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>;\n\n/**\n * Evaluates a feature flag generically, returning an react-flavored queryable object.\n * The resolver method to use is based on the type of the defaultValue.\n * For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails} and equivalents.\n * By default, components will re-render when the flag value changes.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {ReactFlagEvaluationOptions} options for this evaluation\n * @returns { FlagQuery } a queryable object containing useful information about the flag.\n */\nexport function useFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): FlagQuery<\n T extends boolean\n ? boolean\n : T extends number\n ? number\n : T extends string\n ? string\n : T extends JsonValue\n ? T\n : JsonValue\n> {\n // use the default value to determine the resolver to call\n const query =\n typeof defaultValue === 'boolean'\n ? new HookFlagQuery<boolean>(useBooleanFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'number'\n ? new HookFlagQuery<number>(useNumberFlagDetails(flagKey, defaultValue, options))\n : typeof defaultValue === 'string'\n ? new HookFlagQuery<string>(useStringFlagDetails(flagKey, defaultValue, options))\n : new HookFlagQuery<JsonValue>(useObjectFlagDetails(flagKey, defaultValue, options));\n // TS sees this as HookFlagQuery<JsonValue>, because the compiler isn't aware of the `typeof` checks above.\n return query as unknown as ConstrainedFlagQuery<T>;\n}\n\n// alias to the return value of useFlag, used to keep useSuspenseFlag consistent\ntype UseFlagReturn<T extends FlagValue> = ReturnType<typeof useFlag<T>>;\n\n/**\n * Equivalent to {@link useFlag} with `options: { suspend: true }`\n * @experimental Suspense is an experimental feature subject to change in future versions.\n * @param {string} flagKey the flag identifier\n * @template {FlagValue} T A optional generic argument constraining the default.\n * @param {T} defaultValue the default value; used to determine what resolved type should be used.\n * @param {NoSuspenseOptions} options for this evaluation\n * @returns { UseFlagReturn<T> } a queryable object containing useful information about the flag.\n */\nexport function useSuspenseFlag<T extends FlagValue = FlagValue>(\n flagKey: string,\n defaultValue: T,\n options?: NoSuspenseOptions,\n): UseFlagReturn<T> {\n return useFlag(flagKey, defaultValue, { ...options, suspendUntilReady: true, suspendWhileReconciling: true });\n}\n\n/**\n * Evaluates a feature flag, returning a boolean.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagValue(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): boolean {\n return useBooleanFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {boolean} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<boolean>} a EvaluationDetails object for this evaluation\n */\nexport function useBooleanFlagDetails(\n flagKey: string,\n defaultValue: boolean,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<boolean> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getBooleanDetails;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a string.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagValue<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): string {\n return useStringFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {string} [T=string] A optional generic argument constraining the string\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<string>} a EvaluationDetails object for this evaluation\n */\nexport function useStringFlagDetails<T extends string = string>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<string> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getStringDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning a number.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagValue<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): number {\n return useNumberFlagDetails(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {number} [T=number] A optional generic argument constraining the number\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<number>} a EvaluationDetails object for this evaluation\n */\nexport function useNumberFlagDetails<T extends number = number>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<number> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getNumberDetails<T>;\n },\n options,\n );\n}\n\n/**\n * Evaluates a feature flag, returning an object.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {T} defaultValue the default value\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { boolean} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagValue<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): T {\n return useObjectFlagDetails<T>(flagKey, defaultValue, options).value;\n}\n\n/**\n * Evaluates a feature flag, returning evaluation details.\n * By default, components will re-render when the flag value changes.\n * For a generic hook returning a queryable interface, see {@link useFlag}.\n * @param {string} flagKey the flag identifier\n * @param {T} defaultValue the default value\n * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure\n * @param {ReactFlagEvaluationOptions} options options for this evaluation\n * @returns { EvaluationDetails<T>} a EvaluationDetails object for this evaluation\n */\nexport function useObjectFlagDetails<T extends JsonValue = JsonValue>(\n flagKey: string,\n defaultValue: T,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n return attachHandlersAndResolve(\n flagKey,\n defaultValue,\n (client) => {\n return client.getObjectDetails<T>;\n },\n options,\n );\n}\n\n// determines if a flag should be re-evaluated based on a list of changed flags\nfunction shouldEvaluateFlag(flagKey: string, flagsChanged?: string[]): boolean {\n return !!flagsChanged && flagsChanged.includes(flagKey);\n}\n\nfunction attachHandlersAndResolve<T extends FlagValue>(\n flagKey: string,\n defaultValue: T,\n resolver: (\n client: Client,\n ) => (flagKey: string, defaultValue: T, options?: FlagEvaluationOptions) => EvaluationDetails<T>,\n options?: ReactFlagEvaluationOptions,\n): EvaluationDetails<T> {\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n if (defaultedOptions.suspendWhileReconciling && status === ProviderStatus.RECONCILING) {\n suspendUntilReady(client);\n }\n\n const [evaluationDetails, setEvaluationDetails] = useState<EvaluationDetails<T>>(\n resolver(client).call(client, flagKey, defaultValue, options),\n );\n\n // Maintain a mutable reference to the evaluation details to have a up-to-date reference in the handlers.\n const evaluationDetailsRef = useRef<EvaluationDetails<T>>(evaluationDetails);\n useEffect(() => {\n evaluationDetailsRef.current = evaluationDetails;\n }, [evaluationDetails]);\n\n const updateEvaluationDetailsCallback = () => {\n const updatedEvaluationDetails = resolver(client).call(client, flagKey, defaultValue, options);\n\n /**\n * Avoid re-rendering if the value hasn't changed. We could expose a means\n * to define a custom comparison function if users require a more\n * sophisticated comparison in the future.\n */\n if (!isEqual(updatedEvaluationDetails.value, evaluationDetailsRef.current.value)) {\n setEvaluationDetails(updatedEvaluationDetails);\n }\n };\n\n const configurationChangeCallback: EventHandler<ClientProviderEvents.ConfigurationChanged> = (eventDetails) => {\n if (shouldEvaluateFlag(flagKey, eventDetails?.flagsChanged)) {\n updateEvaluationDetailsCallback();\n }\n };\n\n useEffect(() => {\n if (status === ProviderStatus.NOT_READY) {\n // update when the provider is ready\n client.addHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n }\n\n if (defaultedOptions.updateOnContextChanged) {\n // update when the context changes\n client.addHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.Ready, updateEvaluationDetailsCallback);\n client.removeHandler(ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);\n };\n }, []);\n\n useEffect(() => {\n if (defaultedOptions.updateOnConfigurationChanged) {\n // update when the provider configuration changes\n client.addHandler(ProviderEvents.ConfigurationChanged, configurationChangeCallback);\n }\n return () => {\n // cleanup the handlers\n client.removeHandler(ProviderEvents.ConfigurationChanged, configurationChangeCallback);\n };\n }, []);\n\n return evaluationDetails;\n}\n", "import type { Client } from '@openfeature/web-sdk';\nimport React from 'react';\nimport type { NormalizedOptions, ReactFlagEvaluationOptions} from '../common';\nimport { normalizeOptions } from '../common';\n\n/**\n * The underlying React context.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const Context = React.createContext<{ client: Client; domain?: string; options: ReactFlagEvaluationOptions } | undefined>(undefined);\n\n/**\n * Get a normalized copy of the options used for this OpenFeatureProvider, see {@link normalizeOptions}.\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @returns {NormalizedOptions} normalized options the defaulted options, not defaulted or normalized.\n */\nexport function useProviderOptions(): NormalizedOptions {\n const { options } = React.useContext(Context) || {};\n return normalizeOptions(options);\n}\n", "import { type FlagValue } from '@openfeature/web-sdk';\n\n/**\n * Deeply compare two values to determine if they are equal.\n * Supports primitives and serializable objects.\n * @param {FlagValue} value First value to compare\n * @param {FlagValue} other Second value to compare\n * @returns {boolean} True if the values are equal\n */\nexport function isEqual(value: FlagValue, other: FlagValue): boolean {\n if (value === other) {\n return true;\n }\n\n if (typeof value !== typeof other) {\n return false;\n }\n\n if (typeof value === 'object' && value !== null && other !== null) {\n const valueKeys = Object.keys(value);\n const otherKeys = Object.keys(other);\n\n if (valueKeys.length !== otherKeys.length) {\n return false;\n }\n\n for (const key of valueKeys) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!isEqual((value as any)[key], (other as any)[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n", "import type { FlagEvaluationOptions } from '@openfeature/web-sdk';\n\nexport type ReactFlagEvaluationOptions = ({\n /**\n * Enable or disable all suspense functionality.\n * Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspend?: boolean;\n suspendUntilReady?: never;\n suspendWhileReconciling?: never;\n} | {\n /**\n * Suspend flag evaluations while the provider is not ready.\n * Set to false if you don't want to show suspense fallbacks until the provider is initialized.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendUntilReady?: boolean;\n /**\n * Suspend flag evaluations while the provider's context is being reconciled.\n * Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.\n * Defaults to false.\n * Cannot be used in conjunction with `suspend` option.\n * @experimental Suspense is an experimental feature subject to change in future versions.\n */\n suspendWhileReconciling?: boolean;\n suspend?: never;\n}) & {\n /**\n * Update the component if the provider emits a ConfigurationChanged event.\n * Set to false to prevent components from re-rendering when flag value changes\n * are received by the associated provider.\n * Defaults to true.\n */\n updateOnConfigurationChanged?: boolean;\n /**\n * Update the component when the OpenFeature context changes.\n * Set to false to prevent components from re-rendering when attributes which\n * may be factors in flag evaluation change.\n * Defaults to true.\n */\n updateOnContextChanged?: boolean;\n} & FlagEvaluationOptions;\n\nexport type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>;\n\n/**\n * Default options.\n * DO NOT EXPORT PUBLICLY\n * @internal\n */\nexport const DEFAULT_OPTIONS: ReactFlagEvaluationOptions = {\n updateOnContextChanged: true,\n updateOnConfigurationChanged: true,\n suspendUntilReady: false,\n suspendWhileReconciling: false,\n};\n\n/**\n * Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`).\n * DO NOT EXPORT PUBLICLY\n * @internal\n * @param {ReactFlagEvaluationOptions} options options to normalize\n * @returns {NormalizedOptions} normalized options\n */\nexport const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions = (options: ReactFlagEvaluationOptions = {}) => {\n const updateOnContextChanged = options.updateOnContextChanged;\n const updateOnConfigurationChanged = options.updateOnConfigurationChanged;\n\n // fall-back the suspense options to the catch-all `suspend` property \n const suspendUntilReady = 'suspendUntilReady' in options ? options.suspendUntilReady : options.suspend;\n const suspendWhileReconciling = 'suspendWhileReconciling' in options ? options.suspendWhileReconciling : options.suspend;\n\n return {\n // only return these if properly set (no undefined to allow overriding with spread)\n ...(typeof suspendUntilReady === 'boolean' && {suspendUntilReady}),\n ...(typeof suspendWhileReconciling === 'boolean' && {suspendWhileReconciling}),\n ...(typeof updateOnContextChanged === 'boolean' && {updateOnContextChanged}),\n ...(typeof updateOnConfigurationChanged === 'boolean' && {updateOnConfigurationChanged}),\n };\n};\n", "import type { Client} from '@openfeature/web-sdk';\nimport { ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Suspends until the client is ready to evaluate feature flags.\n * DO NOT EXPORT PUBLICLY\n * @param {Client} client OpenFeature client\n */\nexport function suspendUntilReady(client: Client): Promise<void> {\n let resolve: (value: unknown) => void;\n let reject: () => void;\n throw new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n client.addHandler(ProviderEvents.Ready, resolve);\n client.addHandler(ProviderEvents.Error, reject);\n }).finally(() => {\n client.removeHandler(ProviderEvents.Ready, resolve);\n client.removeHandler(ProviderEvents.Ready, reject);\n });\n}\n", "import React from 'react';\nimport { Context } from '../common';\nimport type { Client } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link Client} instance for this OpenFeatureProvider context.\n * Note that the provider to which this is bound is determined by the OpenFeatureProvider's domain.\n * @returns {Client} client for this scope\n */\nexport function useOpenFeatureClient(): Client {\n const { client } = React.useContext(Context) || {};\n\n if (!client) {\n throw new Error(\n 'No OpenFeature client available - components using OpenFeature must be wrapped with an <OpenFeatureProvider>. If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing',\n );\n }\n\n return client;\n}\n", "import { useEffect, useState } from 'react';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport type { ProviderStatus } from '@openfeature/web-sdk';\nimport { ProviderEvents } from '@openfeature/web-sdk';\n\n/**\n * Get the {@link ProviderStatus} for the OpenFeatureClient.\n * @returns {ProviderStatus} status of the client for this scope\n */\nexport function useOpenFeatureClientStatus(): ProviderStatus {\n const client = useOpenFeatureClient();\n const [status, setStatus] = useState(client.providerStatus);\n\n useEffect(() => {\n const updateStatus = () => setStatus(client.providerStatus);\n client.addHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.addHandler(ProviderEvents.ContextChanged, updateStatus);\n client.addHandler(ProviderEvents.Error, updateStatus);\n client.addHandler(ProviderEvents.Ready, updateStatus);\n client.addHandler(ProviderEvents.Stale, updateStatus);\n client.addHandler(ProviderEvents.Reconciling, updateStatus);\n return () => {\n client.removeHandler(ProviderEvents.ConfigurationChanged, updateStatus);\n client.removeHandler(ProviderEvents.ContextChanged, updateStatus);\n client.removeHandler(ProviderEvents.Error, updateStatus);\n client.removeHandler(ProviderEvents.Ready, updateStatus);\n client.removeHandler(ProviderEvents.Stale, updateStatus);\n client.removeHandler(ProviderEvents.Reconciling, updateStatus);\n };\n }, [client]);\n\n return status;\n}\n", "import type {\n EvaluationDetails,\n FlagValue} from '@openfeature/web-sdk';\nimport {\n StandardResolutionReasons\n} from '@openfeature/web-sdk';\nimport type { FlagQuery } from '../query';\n\n\n// FlagQuery implementation, do not export\nexport class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {\n constructor(private _details: EvaluationDetails<T>) {}\n\n get details() {\n return this._details;\n }\n\n get value() {\n return this._details?.value;\n }\n\n get variant() {\n return this._details.variant;\n }\n\n get flagMetadata() {\n return this._details.flagMetadata;\n }\n\n get reason() {\n return this._details.reason;\n }\n\n get isError() {\n return !!this._details?.errorCode || this._details.reason == StandardResolutionReasons.ERROR;\n }\n\n get errorCode() {\n return this._details?.errorCode;\n }\n\n get errorMessage() {\n return this._details?.errorMessage;\n }\n\n get isAuthoritative() {\n return (\n !this.isError &&\n this._details.reason != StandardResolutionReasons.STALE &&\n this._details.reason != StandardResolutionReasons.DISABLED\n );\n }\n\n get type() {\n return typeof this._details.value;\n }\n}\n", "import type { Client} from '@openfeature/web-sdk';\nimport { OpenFeature } from '@openfeature/web-sdk';\nimport * as React from 'react';\nimport type { ReactFlagEvaluationOptions } from '../common';\nimport { Context } from '../common';\n\ntype ClientOrDomain =\n | {\n /**\n * An identifier which logically binds clients with providers\n * @see OpenFeature.setProvider() and overloads.\n */\n domain?: string;\n client?: never;\n }\n | {\n /**\n * OpenFeature client to use.\n */\n client?: Client;\n domain?: never;\n };\n\ntype ProviderProps = {\n children?: React.ReactNode;\n} & ClientOrDomain &\n ReactFlagEvaluationOptions;\n\n /**\n * Provides a scope for evaluating feature flags by binding a client to all child components.\n * @param {ProviderProps} properties props for the context provider\n * @returns {OpenFeatureProvider} context provider\n */\nexport function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps) {\n if (!client) {\n client = OpenFeature.getClient(domain);\n }\n\n return <Context.Provider value={{ client, options, domain }}>{children}</Context.Provider>;\n}\n", "import { ProviderStatus } from '@openfeature/web-sdk';\nimport { useOpenFeatureClient } from './use-open-feature-client';\nimport { useOpenFeatureClientStatus } from './use-open-feature-client-status';\nimport type { ReactFlagEvaluationOptions} from '../common';\nimport { DEFAULT_OPTIONS, useProviderOptions, normalizeOptions, suspendUntilReady } from '../common';\n\ntype Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;\n\n/**\n * Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.\n * Especially useful for React v16/17 \"Legacy Suspense\", in which siblings to suspending components are\n * initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).\n * @param {Options} options options for suspense\n * @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own\n */\nexport function useWhenProviderReady(options?: Options): boolean {\n const client = useOpenFeatureClient();\n const status = useOpenFeatureClientStatus();\n // highest priority > evaluation hook options > provider options > default options > lowest priority\n const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) };\n\n // suspense\n if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) {\n suspendUntilReady(client);\n }\n\n return status === ProviderStatus.READY;\n}\n", "import type {\n JsonValue,\n Provider} from '@openfeature/web-sdk';\nimport {\n InMemoryProvider,\n NOOP_PROVIDER,\n OpenFeature\n} from '@openfeature/web-sdk';\nimport React from 'react';\nimport type { NormalizedOptions } from '../common';\nimport { OpenFeatureProvider } from './provider';\n\ntype FlagValueMap = { [flagKey: string]: JsonValue };\ntype FlagConfig = ConstructorParameters<typeof InMemoryProvider>[0];\ntype TestProviderProps = Omit<React.ComponentProps<typeof OpenFeatureProvider>, 'client'> &\n (\n | {\n provider?: never;\n /**\n * Optional map of flagKeys to flagValues for this OpenFeatureTestProvider context.\n * If not supplied, all flag evaluations will default.\n */\n flagValueMap?: FlagValueMap;\n /**\n * Optional delay for the underlying test provider's readiness and reconciliation.\n * Defaults to 0.\n */\n delayMs?: number;\n }\n | {\n /**\n * An optional partial provider to pass for full control over the flag resolution for this OpenFeatureTestProvider context.\n * Any un-implemented methods or properties will no-op.\n */\n provider?: Partial<Provider>;\n flagValueMap?: never;\n delayMs?: never;\n }\n );\n\n const TEST_VARIANT = 'test-variant';\n const TEST_PROVIDER = 'test-provider';\n\n// internal provider which is basically the in-memory provider with a simpler config and some optional fake delays\nclass TestProvider extends InMemoryProvider {\n\n // initially make this undefined, we still set it if a delay is specified\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - For maximum compatibility with previous versions, we ignore a possible TS error here,\n // since \"initialize\" was previously defined in superclass.\n // We can safely remove this ts-ignore in a few versions\n initialize: Provider['initialize'] = undefined;\n\n // \"place-holder\" init function which we only assign if want a delay\n private delayedInitialize = async () => {\n await new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n };\n\n constructor(\n flagValueMap: FlagValueMap,\n private delay = 0,\n ) {\n // convert the simple flagValueMap into an in-memory config\n const flagConfig = Object.entries(flagValueMap).reduce((acc: FlagConfig, flag): FlagConfig => {\n return {\n ...acc,\n [flag[0]]: {\n variants: {\n [TEST_VARIANT]: flag[1],\n },\n defaultVariant: TEST_VARIANT,\n disabled: false,\n },\n };\n }, {});\n super(flagConfig);\n // only define and init if there's a non-zero delay specified\n this.initialize = this.delay ? this.delayedInitialize.bind(this) : undefined;\n }\n\n async onContextChange() {\n return new Promise<void>((resolve) => setTimeout(resolve, this.delay));\n }\n}\n\n/**\n * A React Context provider based on the {@link InMemoryProvider}, specifically built for testing.\n * Use this for testing components that use flag evaluation hooks.\n * @param {TestProviderProps} testProviderOptions options for the OpenFeatureTestProvider\n * @returns {OpenFeatureProvider} OpenFeatureTestProvider\n */\nexport function OpenFeatureTestProvider(testProviderOptions: TestProviderProps) {\n const { flagValueMap, provider } = testProviderOptions;\n const effectiveProvider = (\n flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) || NOOP_PROVIDER\n ) as Provider;\n testProviderOptions.domain\n ? OpenFeature.setProvider(testProviderOptions.domain, effectiveProvider)\n : OpenFeature.setProvider(effectiveProvider);\n\n return (\n <OpenFeatureProvider {...(testProviderOptions as NormalizedOptions)} domain={testProviderOptions.domain}>\n {testProviderOptions.children}\n </OpenFeatureProvider>\n );\n}\n\n// mix in the no-op provider when the partial is passed\nfunction mixInNoop(provider: Partial<Provider> = {}) {\n // fill in any missing methods with no-ops\n for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(NOOP_PROVIDER)).filter(prop => prop !== 'constructor')) {\n const patchedProvider = provider as {[key: string]: keyof Provider};\n if (!Object.getPrototypeOf(patchedProvider)[prop] && !patchedProvider[prop]) {\n patchedProvider[prop] = Object.getPrototypeOf(NOOP_PROVIDER)[prop];\n }\n }\n // fill in the metadata if missing\n if (!provider.metadata || !provider.metadata.name) {\n (provider.metadata as unknown) = { name: TEST_PROVIDER };\n }\n return provider;\n}\n", "import { useCallback, useContext, useRef } from 'react';\nimport type { EvaluationContext } from '@openfeature/web-sdk';\nimport { OpenFeature } from '@openfeature/web-sdk';\nimport { Context } from '../common';\n\nexport type ContextMutationOptions = {\n /**\n * Mutate the default context instead of the domain scoped context applied at the `<OpenFeatureProvider/>`.\n * Note, if the `<OpenFeatureProvider/>` has no domain specified, the default is used.\n * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#manage-evaluation-context-for-domains|documentation} for more information.\n * @default false\n */\n defaultContext?: boolean;\n};\n\nexport type ContextMutation = {\n /**\n * Context-aware function to set the desired context (see: {@link ContextMutationOptions} for details).\n * There's generally no need to await the result of this function; flag evaluation hooks will re-render when the context is updated.\n * This promise never rejects.\n * @param updatedContext\n * @returns Promise for awaiting the context update\n */\n setContext: (updatedContext: EvaluationContext) => Promise<void>;\n};\n\n/**\n * Get context-aware tracking function(s) for mutating the evaluation context associated with this domain, or the default context if `defaultContext: true`.\n * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#targeting-and-context|documentation} for more information.\n * @param {ContextMutationOptions} options options for the generated function\n * @returns {ContextMutation} context-aware function(s) to mutate evaluation context\n */\nexport function useContextMutator(options: ContextMutationOptions = { defaultContext: false }): ContextMutation {\n const { domain } = useContext(Context) || {};\n const previousContext = useRef<null | EvaluationContext>(null);\n\n const setContext = useCallback(async (updatedContext: EvaluationContext) => {\n if (previousContext.current !== updatedContext) {\n if (!domain || options?.defaultContext) {\n OpenFeature.setContext(updatedContext);\n } else {\n OpenFeature.setContext(domain, updatedContext);\n }\n previousContext.current = updatedContext;\n }\n }, [domain]);\n\n return {\n setContext,\n };\n}\n", "import type { Tracking, TrackingEventDetails } from '@openfeature/web-sdk';\nimport { useCallback } from 'react';\nimport { useOpenFeatureClient } from '../provider';\n\nexport type Track = {\n /**\n * Context-aware tracking function for the parent `<OpenFeatureProvider/>`.\n * Track a user action or application state, usually representing a business objective or outcome.\n * @param trackingEventName an identifier for the event\n * @param trackingEventDetails the details of the tracking event\n */\n track: Tracking['track'];\n};\n\n/**\n * Get a context-aware tracking function.\n * @returns {Track} context-aware tracking\n */\nexport function useTrack(): Track {\n const client = useOpenFeatureClient();\n\n const track = useCallback((trackingEventName: string, trackingEventDetails?: TrackingEventDetails) => {\n client.track(trackingEventName, trackingEventDetails);\n }, []);\n\n return {\n track,\n };\n}\n", "export * from './evaluation';\nexport * from './query';\nexport * from './provider';\nexport * from './context';\nexport * from './tracking';\n// re-export the web-sdk so consumers can access that API from the react-sdk\nexport * from '@openfeature/web-sdk';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;AAAA,EACE,kBAAAA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAAC,YAAW,QAAQ,YAAAC,iBAAgB;;;ACX5C,OAAO,WAAW;AASX,IAAM,UAAU,MAAM,cAAoG,MAAS;AAQnI,SAAS,qBAAwC;AACtD,QAAM,EAAE,QAAQ,IAAI,MAAM,WAAW,OAAO,KAAK,CAAC;AAClD,SAAO,iBAAiB,OAAO;AACjC;;;ACZO,SAAS,QAAQ,OAAkB,OAA2B;AACnE,MAAI,UAAU,OAAO;AACnB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,OAAO,OAAO;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,MAAM;AACjE,UAAM,YAAY,OAAO,KAAK,KAAK;AACnC,UAAM,YAAY,OAAO,KAAK,KAAK;AAEnC,QAAI,UAAU,WAAW,UAAU,QAAQ;AACzC,aAAO;AAAA,IACT;AAEA,eAAW,OAAO,WAAW;AAE3B,UAAI,CAAC,QAAS,MAAc,GAAG,GAAI,MAAc,GAAG,CAAC,GAAG;AACtD,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;ACgBO,IAAM,kBAA8C;AAAA,EACzD,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,mBAAmB;AAAA,EACnB,yBAAyB;AAC3B;AASO,IAAM,mBAAgF,CAAC,UAAsC,CAAC,MAAM;AACzI,QAAM,yBAAyB,QAAQ;AACvC,QAAM,+BAA+B,QAAQ;AAG7C,QAAMC,qBAAoB,uBAAuB,UAAU,QAAQ,oBAAoB,QAAQ;AAC/F,QAAM,0BAA0B,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E,IAAI,KAAK,CAAC,gBAAgB,IAAI,GAAG;AAC3E,sBAAgB,IAAI,IAAI,OAAO,eAAe,aAAa,EAAE,IAAI;AAAA,IACnE;AAAA,EACF;AAEA,MAAI,CAAC,SAAS,YAAY,CAAC,SAAS,SAAS,MAAM;AACjD,IAAC,SAAS,WAAuB,EAAE,MAAM,cAAc;AAAA,EACzD;AACA,SAAO;AACT;;;ACzHA,SAAS,aAAa,YAAY,UAAAC,eAAc;AAEhD,SAAS,eAAAC,oBAAmB;AA8BrB,SAAS,kBAAkB,UAAkC,EAAE,gBAAgB,MAAM,GAAoB;AAC5G,QAAM,EAAE,OAAO,IAAI,WAAW,OAAO,KAAK,CAAC;AAC3C,QAAM,kBAAkBC,QAAiC,IAAI;AAE7D,QAAM,aAAa,YAAY,CAAO,mBAAsC;AACxE,QAAI,gBAAgB,YAAY,gBAAgB;AAC5C,UAAI,CAAC,WAAU,mCAAS,iBAAgB;AACpC,QAAAC,aAAY,WAAW,cAAc;AAAA,MACzC,OAAO;AACH,QAAAA,aAAY,WAAW,QAAQ,cAAc;AAAA,MACjD;AACA,sBAAgB,UAAU;AAAA,IAC9B;AAAA,EACJ,IAAG,CAAC,MAAM,CAAC;AAEX,SAAO;AAAA,IACH;AAAA,EACJ;AACJ;;;ACjDA,SAAS,eAAAC,oBAAmB;AAiBrB,SAAS,WAAkB;AAChC,QAAM,SAAS,qBAAqB;AAEpC,QAAM,QAAQC,aAAY,CAAC,mBAA2B,yBAAgD;AACpG,WAAO,MAAM,mBAAmB,oBAAoB;AAAA,EACtD,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;ACtBA,cAAc;",
|
|
6
|
+
"names": ["ProviderEvents", "useEffect", "useState", "suspendUntilReady", "React", "React", "ProviderEvents", "useState", "useEffect", "ProviderEvents", "React", "ProviderStatus", "ProviderStatus", "OpenFeature", "React", "OpenFeature", "React", "prop", "useRef", "OpenFeature", "useRef", "OpenFeature", "useCallback", "useCallback"]
|
|
7
7
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlagEvaluationOptions, FlagValue as FlagValue$1, JsonValue, EvaluationDetails as EvaluationDetails$1, Client, Provider } from '@openfeature/web-sdk';
|
|
1
|
+
import { FlagEvaluationOptions, FlagValue as FlagValue$1, JsonValue, EvaluationDetails as EvaluationDetails$1, Client, Provider, EvaluationContext, Tracking } from '@openfeature/web-sdk';
|
|
2
2
|
export * from '@openfeature/web-sdk';
|
|
3
3
|
import { FlagValue, EvaluationDetails, FlagMetadata, StandardResolutionReasons, ErrorCode } from '@openfeature/core';
|
|
4
4
|
import * as React from 'react';
|
|
@@ -280,4 +280,46 @@ type TestProviderProps = Omit<React__default.ComponentProps<typeof OpenFeaturePr
|
|
|
280
280
|
*/
|
|
281
281
|
declare function OpenFeatureTestProvider(testProviderOptions: TestProviderProps): React__default.JSX.Element;
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
type ContextMutationOptions = {
|
|
284
|
+
/**
|
|
285
|
+
* Mutate the default context instead of the domain scoped context applied at the `<OpenFeatureProvider/>`.
|
|
286
|
+
* Note, if the `<OpenFeatureProvider/>` has no domain specified, the default is used.
|
|
287
|
+
* See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#manage-evaluation-context-for-domains|documentation} for more information.
|
|
288
|
+
* @default false
|
|
289
|
+
*/
|
|
290
|
+
defaultContext?: boolean;
|
|
291
|
+
};
|
|
292
|
+
type ContextMutation = {
|
|
293
|
+
/**
|
|
294
|
+
* Context-aware function to set the desired context (see: {@link ContextMutationOptions} for details).
|
|
295
|
+
* There's generally no need to await the result of this function; flag evaluation hooks will re-render when the context is updated.
|
|
296
|
+
* This promise never rejects.
|
|
297
|
+
* @param updatedContext
|
|
298
|
+
* @returns Promise for awaiting the context update
|
|
299
|
+
*/
|
|
300
|
+
setContext: (updatedContext: EvaluationContext) => Promise<void>;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Get context-aware tracking function(s) for mutating the evaluation context associated with this domain, or the default context if `defaultContext: true`.
|
|
304
|
+
* See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#targeting-and-context|documentation} for more information.
|
|
305
|
+
* @param {ContextMutationOptions} options options for the generated function
|
|
306
|
+
* @returns {ContextMutation} context-aware function(s) to mutate evaluation context
|
|
307
|
+
*/
|
|
308
|
+
declare function useContextMutator(options?: ContextMutationOptions): ContextMutation;
|
|
309
|
+
|
|
310
|
+
type Track = {
|
|
311
|
+
/**
|
|
312
|
+
* Context-aware tracking function for the parent `<OpenFeatureProvider/>`.
|
|
313
|
+
* Track a user action or application state, usually representing a business objective or outcome.
|
|
314
|
+
* @param trackingEventName an identifier for the event
|
|
315
|
+
* @param trackingEventDetails the details of the tracking event
|
|
316
|
+
*/
|
|
317
|
+
track: Tracking['track'];
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Get a context-aware tracking function.
|
|
321
|
+
* @returns {Track} context-aware tracking
|
|
322
|
+
*/
|
|
323
|
+
declare function useTrack(): Track;
|
|
324
|
+
|
|
325
|
+
export { type ContextMutation, type ContextMutationOptions, type FlagQuery, OpenFeatureProvider, OpenFeatureTestProvider, type Track, useBooleanFlagDetails, useBooleanFlagValue, useContextMutator, useFlag, useNumberFlagDetails, useNumberFlagValue, useObjectFlagDetails, useObjectFlagValue, useOpenFeatureClient, useStringFlagDetails, useStringFlagValue, useSuspenseFlag, useTrack, useWhenProviderReady };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/react-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "OpenFeature React SDK",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "jest --verbose",
|
|
18
18
|
"lint": "eslint ./",
|
|
19
|
+
"lint:fix": "eslint ./ --fix",
|
|
19
20
|
"clean": "shx rm -rf ./dist",
|
|
20
21
|
"build:react-esm": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
|
|
21
22
|
"build:react-cjs": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
|
|
@@ -46,11 +47,11 @@
|
|
|
46
47
|
},
|
|
47
48
|
"homepage": "https://github.com/open-feature/js-sdk#readme",
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@openfeature/web-sdk": "^1.
|
|
50
|
+
"@openfeature/web-sdk": "^1.3.0",
|
|
50
51
|
"react": ">=16.8.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@openfeature/core": "*",
|
|
54
55
|
"@openfeature/web-sdk": "*"
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
|
+
}
|