@shiva004/surveys 0.12.0 → 0.12.1

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.
Files changed (42) hide show
  1. package/dist/elements.js +9644 -8690
  2. package/dist/flags/OpenFeatureFlags.d.ts +21 -0
  3. package/dist/flags/data.d.ts +13 -1
  4. package/dist/flags/openfeature.d.ts +36 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.js +6949 -5994
  7. package/dist/logs/data.d.ts +8 -0
  8. package/dist/openfeature/context/index.d.ts +1 -0
  9. package/dist/openfeature/context/use-context-mutator.d.ts +27 -0
  10. package/dist/openfeature/declarative/FeatureFlag.d.ts +68 -0
  11. package/dist/openfeature/declarative/index.d.ts +1 -0
  12. package/dist/openfeature/evaluation/index.d.ts +1 -0
  13. package/dist/openfeature/evaluation/use-feature-flag.d.ts +113 -0
  14. package/dist/openfeature/index.d.ts +8 -0
  15. package/dist/openfeature/internal/context.d.ts +21 -0
  16. package/dist/openfeature/internal/errors.d.ts +3 -0
  17. package/dist/openfeature/internal/hook-flag-query.d.ts +16 -0
  18. package/dist/openfeature/internal/index.d.ts +4 -0
  19. package/dist/openfeature/internal/is-equal.d.ts +11 -0
  20. package/dist/openfeature/internal/options.d.ts +15 -0
  21. package/dist/openfeature/internal/suspense.d.ts +18 -0
  22. package/dist/openfeature/internal/use.d.ts +19 -0
  23. package/dist/openfeature/options.d.ts +46 -0
  24. package/dist/openfeature/provider/index.d.ts +5 -0
  25. package/dist/openfeature/provider/provider.d.ts +27 -0
  26. package/dist/openfeature/provider/test-provider.d.ts +35 -0
  27. package/dist/openfeature/provider/use-open-feature-client-status.d.ts +7 -0
  28. package/dist/openfeature/provider/use-open-feature-client.d.ts +7 -0
  29. package/dist/openfeature/provider/use-open-feature-provider.d.ts +8 -0
  30. package/dist/openfeature/provider/use-when-provider-ready.d.ts +14 -0
  31. package/dist/openfeature/query/index.d.ts +1 -0
  32. package/dist/openfeature/query/query.d.ts +48 -0
  33. package/dist/openfeature/sdk/api.d.ts +43 -0
  34. package/dist/openfeature/sdk/client.d.ts +46 -0
  35. package/dist/openfeature/sdk/errors.d.ts +38 -0
  36. package/dist/openfeature/sdk/events.d.ts +10 -0
  37. package/dist/openfeature/sdk/index.d.ts +8 -0
  38. package/dist/openfeature/sdk/providers.d.ts +46 -0
  39. package/dist/openfeature/sdk/types.d.ts +168 -0
  40. package/dist/openfeature/tracking/index.d.ts +1 -0
  41. package/dist/openfeature/tracking/use-track.d.ts +15 -0
  42. package/package.json +1 -1
@@ -8,6 +8,8 @@ export interface LogLine {
8
8
  m: string;
9
9
  stack?: string;
10
10
  src?: string;
11
+ /** Set when a framework (Angular ErrorHandler, zone.js) swallowed an uncaught error and only logged it to console.error. */
12
+ fw?: 'error' | 'rejection';
11
13
  }
12
14
  export interface LogFile {
13
15
  name: string;
@@ -49,6 +51,12 @@ declare global {
49
51
  __pulseLogsCapture?: boolean;
50
52
  }
51
53
  }
54
+ /**
55
+ * The same uncaught error can arrive twice (window event + framework console.error). Returns false only when the same
56
+ * message was already taken in the last second by the OTHER origin, so genuine repeats from one origin still count.
57
+ * @internal
58
+ */
59
+ export declare const claimUncaught: (channel: string, origin: "win" | "fw", message: string) => boolean;
52
60
  export declare function createLogger(source: string): Logger;
53
61
  export declare const logger: Logger;
54
62
  export declare const subscribe: (fn: () => void) => () => void;
@@ -0,0 +1 @@
1
+ export * from './use-context-mutator';
@@ -0,0 +1,27 @@
1
+ import type { EvaluationContext } from '../sdk';
2
+ export type ContextMutationOptions = {
3
+ /**
4
+ * Mutate the default context instead of the domain scoped context applied at the `<OpenFeatureProvider/>`.
5
+ * By default, will use the domain set on `<OpenFeatureProvider/>` (or the domain associated with the client set on `<OpenFeatureProvider/>`).
6
+ * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#manage-evaluation-context-for-domains|documentation} for more information.
7
+ * @default false
8
+ */
9
+ defaultContext?: boolean;
10
+ };
11
+ export type ContextMutation = {
12
+ /**
13
+ * Context-aware function to set the desired context (see: {@link ContextMutationOptions} for details).
14
+ * There's generally no need to await the result of this function; flag evaluation hooks will re-render when the context is updated.
15
+ * This promise never rejects.
16
+ * @param updatedContext New context object or method to generate it from the current context
17
+ * @returns Promise for awaiting the context update
18
+ */
19
+ setContext: (updatedContext: EvaluationContext | ((currentContext: EvaluationContext) => EvaluationContext)) => Promise<void>;
20
+ };
21
+ /**
22
+ * Get context-aware tracking function(s) for mutating the evaluation context associated with this domain, or the default context if `defaultContext: true`.
23
+ * See the {@link https://openfeature.dev/docs/reference/technologies/client/web/#targeting-and-context|documentation} for more information.
24
+ * @param {ContextMutationOptions} options options for the generated function
25
+ * @returns {ContextMutation} context-aware function(s) to mutate evaluation context
26
+ */
27
+ export declare function useContextMutator(options?: ContextMutationOptions): ContextMutation;
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import type { FlagQuery } from '../query';
3
+ import type { FlagValue, EvaluationDetails, ConstrainedFlagKey } from '../sdk';
4
+ import type { ReactFlagEvaluationOptions } from '../options';
5
+ /**
6
+ * Props for the FeatureFlag component that conditionally renders content based on feature flag state.
7
+ * @interface FeatureFlagProps
8
+ */
9
+ interface FeatureFlagProps<T extends FlagValue = FlagValue> {
10
+ /**
11
+ * The key of the feature flag to evaluate.
12
+ */
13
+ flagKey: ConstrainedFlagKey<T>;
14
+ /**
15
+ * Optional predicate function for custom matching logic.
16
+ * If provided, this function will be used instead of the default equality check.
17
+ * @param matchValue The value to match (matchValue prop)
18
+ * @param details The evaluation details
19
+ * @returns true if the condition is met, false otherwise
20
+ */
21
+ predicate?: (matchValue: T | undefined, details: EvaluationDetails<T>) => boolean;
22
+ /**
23
+ * Content to render when the feature flag condition is met.
24
+ * Can be a React node or a function that receives flag query details and returns a React node.
25
+ */
26
+ children: React.ReactNode | ((details: FlagQuery<T>) => React.ReactNode);
27
+ /**
28
+ * Optional content to render when the feature flag condition is not met.
29
+ * Can be a React node or a function that receives evaluation details and returns a React node.
30
+ */
31
+ fallback?: React.ReactNode | ((details: EvaluationDetails<T>) => React.ReactNode);
32
+ /**
33
+ * Flag evaluation options that will be passed to useFlag hook.
34
+ */
35
+ evaluationOptions?: ReactFlagEvaluationOptions;
36
+ }
37
+ /**
38
+ * Configuration for matching flag values.
39
+ * For boolean flags, `match` is optional (defaults to checking truthiness).
40
+ * For non-boolean flags (string, number, object), `match` is required to determine when to render.
41
+ */
42
+ type FeatureFlagMatchConfig<T extends FlagValue> = {
43
+ /**
44
+ * Default value to use when the feature flag is not found.
45
+ */
46
+ defaultValue: T;
47
+ } & (T extends boolean ? {
48
+ /**
49
+ * Optional value to match against the feature flag value.
50
+ */
51
+ matchValue?: T | undefined;
52
+ } : {
53
+ /**
54
+ * Value to match against the feature flag value.
55
+ * Required for non-boolean flags to determine when children should render.
56
+ * By default, strict equality is used for comparison.
57
+ */
58
+ matchValue: T;
59
+ });
60
+ type FeatureFlagComponentProps<T extends FlagValue> = FeatureFlagProps<T> & FeatureFlagMatchConfig<T>;
61
+ /**
62
+ * @experimental This API is experimental, and is subject to change.
63
+ * FeatureFlag component that conditionally renders its children based on the evaluation of a feature flag.
64
+ * @param {FeatureFlagComponentProps} props The properties for the FeatureFlag component.
65
+ * @returns {React.ReactElement | null} The rendered component or null if the feature is not enabled.
66
+ */
67
+ export declare function FeatureFlag<T extends FlagValue = FlagValue>({ flagKey, matchValue, predicate, defaultValue, children, evaluationOptions, fallback, }: FeatureFlagComponentProps<T>): React.ReactElement | null;
68
+ export {};
@@ -0,0 +1 @@
1
+ export * from './FeatureFlag';
@@ -0,0 +1 @@
1
+ export * from './use-feature-flag';
@@ -0,0 +1,113 @@
1
+ import type { BooleanFlagKey, ConstrainedFlagKey, EvaluationDetails, FlagValue, JsonValue, NumberFlagKey, ObjectFlagKey, StringFlagKey } from '../sdk';
2
+ import type { ReactFlagEvaluationNoSuspenseOptions, ReactFlagEvaluationOptions } from '../options';
3
+ import type { FlagQuery } from '../query';
4
+ /**
5
+ * Evaluates a feature flag generically, returning an react-flavored queryable object.
6
+ * The resolver method to use is based on the type of the defaultValue.
7
+ * For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails} and equivalents.
8
+ * By default, components will re-render when the flag value changes.
9
+ * @param {ConstrainedFlagKey<T>} flagKey the flag identifier
10
+ * @template {FlagValue} T A optional generic argument constraining the default.
11
+ * @param {T} defaultValue the default value; used to determine what resolved type should be used.
12
+ * @param {ReactFlagEvaluationOptions} options for this evaluation
13
+ * @returns { FlagQuery } a queryable object containing useful information about the flag.
14
+ */
15
+ export declare function useFlag<T extends FlagValue = FlagValue>(flagKey: ConstrainedFlagKey<T>, defaultValue: T, options?: ReactFlagEvaluationOptions): FlagQuery<T extends boolean ? boolean : T extends number ? number : T extends string ? string : T extends JsonValue ? T : JsonValue>;
16
+ type UseFlagReturn<T extends FlagValue> = ReturnType<typeof useFlag<T>>;
17
+ /**
18
+ * Equivalent to {@link useFlag} with `options: { suspend: true }`
19
+ * @experimental Suspense is an experimental feature subject to change in future versions.
20
+ * @param {ConstrainedFlagKey<T>} flagKey the flag identifier
21
+ * @template {FlagValue} T A optional generic argument constraining the default.
22
+ * @param {T} defaultValue the default value; used to determine what resolved type should be used.
23
+ * @param {ReactFlagEvaluationNoSuspenseOptions} options for this evaluation
24
+ * @returns { UseFlagReturn<T> } a queryable object containing useful information about the flag.
25
+ */
26
+ export declare function useSuspenseFlag<T extends FlagValue = FlagValue>(flagKey: ConstrainedFlagKey<T>, defaultValue: T, options?: ReactFlagEvaluationNoSuspenseOptions): UseFlagReturn<T>;
27
+ /**
28
+ * Evaluates a feature flag, returning a boolean.
29
+ * By default, components will re-render when the flag value changes.
30
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
31
+ * @param {BooleanFlagKey} flagKey the flag identifier
32
+ * @param {boolean} defaultValue the default value
33
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
34
+ * @returns { boolean} a EvaluationDetails object for this evaluation
35
+ */
36
+ export declare function useBooleanFlagValue(flagKey: BooleanFlagKey, defaultValue: boolean, options?: ReactFlagEvaluationOptions): boolean;
37
+ /**
38
+ * Evaluates a feature flag, returning evaluation details.
39
+ * By default, components will re-render when the flag value changes.
40
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
41
+ * @param {BooleanFlagKey} flagKey the flag identifier
42
+ * @param {boolean} defaultValue the default value
43
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
44
+ * @returns { EvaluationDetails<boolean>} a EvaluationDetails object for this evaluation
45
+ */
46
+ export declare function useBooleanFlagDetails(flagKey: BooleanFlagKey, defaultValue: boolean, options?: ReactFlagEvaluationOptions): EvaluationDetails<boolean>;
47
+ /**
48
+ * Evaluates a feature flag, returning a string.
49
+ * By default, components will re-render when the flag value changes.
50
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
51
+ * @param {StringFlagKey} flagKey the flag identifier
52
+ * @template {string} [T=string] A optional generic argument constraining the string
53
+ * @param {T} defaultValue the default value
54
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
55
+ * @returns { boolean} a EvaluationDetails object for this evaluation
56
+ */
57
+ export declare function useStringFlagValue<T extends string = string>(flagKey: StringFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): string;
58
+ /**
59
+ * Evaluates a feature flag, returning evaluation details.
60
+ * By default, components will re-render when the flag value changes.
61
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
62
+ * @param {StringFlagKey} flagKey the flag identifier
63
+ * @template {string} [T=string] A optional generic argument constraining the string
64
+ * @param {T} defaultValue the default value
65
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
66
+ * @returns { EvaluationDetails<string>} a EvaluationDetails object for this evaluation
67
+ */
68
+ export declare function useStringFlagDetails<T extends string = string>(flagKey: StringFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): EvaluationDetails<string>;
69
+ /**
70
+ * Evaluates a feature flag, returning a number.
71
+ * By default, components will re-render when the flag value changes.
72
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
73
+ * @param {NumberFlagKey} flagKey the flag identifier
74
+ * @template {number} [T=number] A optional generic argument constraining the number
75
+ * @param {T} defaultValue the default value
76
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
77
+ * @returns { boolean} a EvaluationDetails object for this evaluation
78
+ */
79
+ export declare function useNumberFlagValue<T extends number = number>(flagKey: NumberFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): number;
80
+ /**
81
+ * Evaluates a feature flag, returning evaluation details.
82
+ * By default, components will re-render when the flag value changes.
83
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
84
+ * @param {NumberFlagKey} flagKey the flag identifier
85
+ * @template {number} [T=number] A optional generic argument constraining the number
86
+ * @param {T} defaultValue the default value
87
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
88
+ * @returns { EvaluationDetails<number>} a EvaluationDetails object for this evaluation
89
+ */
90
+ export declare function useNumberFlagDetails<T extends number = number>(flagKey: NumberFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): EvaluationDetails<number>;
91
+ /**
92
+ * Evaluates a feature flag, returning an object.
93
+ * By default, components will re-render when the flag value changes.
94
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
95
+ * @param {ObjectFlagKey} flagKey the flag identifier
96
+ * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure
97
+ * @param {T} defaultValue the default value
98
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
99
+ * @returns { boolean} a EvaluationDetails object for this evaluation
100
+ */
101
+ export declare function useObjectFlagValue<T extends JsonValue = JsonValue>(flagKey: ObjectFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): T;
102
+ /**
103
+ * Evaluates a feature flag, returning evaluation details.
104
+ * By default, components will re-render when the flag value changes.
105
+ * For a generic hook returning a queryable interface, see {@link useFlag}.
106
+ * @param {ObjectFlagKey} flagKey the flag identifier
107
+ * @param {T} defaultValue the default value
108
+ * @template {JsonValue} [T=JsonValue] A optional generic argument describing the structure
109
+ * @param {ReactFlagEvaluationOptions} options options for this evaluation
110
+ * @returns { EvaluationDetails<T>} a EvaluationDetails object for this evaluation
111
+ */
112
+ export declare function useObjectFlagDetails<T extends JsonValue = JsonValue>(flagKey: ObjectFlagKey, defaultValue: T, options?: ReactFlagEvaluationOptions): EvaluationDetails<T>;
113
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './declarative';
2
+ export * from './evaluation';
3
+ export * from './query';
4
+ export * from './provider';
5
+ export * from './context';
6
+ export * from './tracking';
7
+ export * from './options';
8
+ export * from './sdk';
@@ -0,0 +1,21 @@
1
+ import type { Client } from '../sdk';
2
+ import React from 'react';
3
+ import type { NormalizedOptions, ReactFlagEvaluationOptions } from '../options';
4
+ /**
5
+ * The underlying React context.
6
+ *
7
+ * **DO NOT EXPORT PUBLICLY**
8
+ * @internal
9
+ */
10
+ export declare const Context: React.Context<{
11
+ client: Client;
12
+ options: ReactFlagEvaluationOptions;
13
+ } | undefined>;
14
+ /**
15
+ * Get a normalized copy of the options used for this OpenFeatureProvider, see {@link normalizeOptions}.
16
+ *
17
+ * **DO NOT EXPORT PUBLICLY**
18
+ * @internal
19
+ * @returns {NormalizedOptions} normalized options the defaulted options, not defaulted or normalized.
20
+ */
21
+ export declare function useProviderOptions(): NormalizedOptions;
@@ -0,0 +1,3 @@
1
+ export declare class MissingContextError extends Error {
2
+ constructor(reason: string);
3
+ }
@@ -0,0 +1,16 @@
1
+ import type { EvaluationDetails, FlagValue } from '../sdk';
2
+ import type { FlagQuery } from '../query';
3
+ export declare class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery {
4
+ private _details;
5
+ constructor(_details: EvaluationDetails<T>);
6
+ get details(): EvaluationDetails<T>;
7
+ get value(): T;
8
+ get variant(): string | undefined;
9
+ get flagMetadata(): Readonly<import("..").FlagMetadata> & import("..").FlagMetadata;
10
+ get reason(): import("..").ResolutionReason | undefined;
11
+ get isError(): boolean;
12
+ get errorCode(): import("..").ErrorCode | undefined;
13
+ get errorMessage(): string | undefined;
14
+ get isAuthoritative(): boolean;
15
+ get type(): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
16
+ }
@@ -0,0 +1,4 @@
1
+ export * from './context';
2
+ export * from './is-equal';
3
+ export * from './options';
4
+ export * from './suspense';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Deeply compare two values to determine if they are equal.
3
+ * Supports primitives and serializable objects.
4
+ *
5
+ * Note: Does not handle Date, RegExp, Map, Set, or circular references.
6
+ * Suitable for comparing EvaluationDetails and other JSON-serializable data.
7
+ * @param {unknown} value First value to compare
8
+ * @param {unknown} other Second value to compare
9
+ * @returns {boolean} True if the values are equal
10
+ */
11
+ export declare function isEqual(value: unknown, other: unknown): boolean;
@@ -0,0 +1,15 @@
1
+ import type { ReactFlagEvaluationOptions, NormalizedOptions } from '../options';
2
+ /**
3
+ * Default options.
4
+ * DO NOT EXPORT PUBLICLY
5
+ * @internal
6
+ */
7
+ export declare const DEFAULT_OPTIONS: ReactFlagEvaluationOptions;
8
+ /**
9
+ * Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`).
10
+ * DO NOT EXPORT PUBLICLY
11
+ * @internal
12
+ * @param {ReactFlagEvaluationOptions} options options to normalize
13
+ * @returns {NormalizedOptions} normalized options
14
+ */
15
+ export declare const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions;
@@ -0,0 +1,18 @@
1
+ import type { Client, Provider } from '../sdk';
2
+ /**
3
+ * Suspends until the client is ready to evaluate feature flags.
4
+ *
5
+ * **DO NOT EXPORT PUBLICLY**
6
+ * @internal
7
+ * @param {Provider} provider the provider to suspend for
8
+ * @param {Client} client the client to check for readiness
9
+ */
10
+ export declare function suspendUntilInitialized(provider: Provider, client: Client): void;
11
+ /**
12
+ * Suspends until the provider has finished reconciling.
13
+ *
14
+ * **DO NOT EXPORT PUBLICLY**
15
+ * @internal
16
+ * @param {Client} client the client to check for readiness
17
+ */
18
+ export declare function suspendUntilReconciled(client: Client): void;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ /**
3
+ * Extends a Promise-like value to include status tracking.
4
+ * The extra properties are used to manage the lifecycle of the Promise, indicating its current state.
5
+ * More information can be found in the React RFE for the use hook.
6
+ * @see https://github.com/reactjs/rfcs/pull/229
7
+ */
8
+ export type UsePromise<T> = Promise<T> & {
9
+ status?: 'pending' | 'fulfilled' | 'rejected';
10
+ value?: T;
11
+ reason?: unknown;
12
+ };
13
+ /**
14
+ * React.use is a React API that lets you read the value of a resource like a Promise or context.
15
+ * It was officially added in React 19, so needs to be polyfilled to support older React versions.
16
+ * @param {UsePromise} thenable A thenable object that represents a Promise-like value.
17
+ * @returns {unknown} The resolved value of the thenable or throws if it's still pending or rejected.
18
+ */
19
+ export declare const use: typeof React.use;
@@ -0,0 +1,46 @@
1
+ import type { FlagEvaluationOptions } from './sdk';
2
+ export type ReactFlagEvaluationOptions = ({
3
+ /**
4
+ * Enable or disable all suspense functionality.
5
+ * Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options.
6
+ * @experimental Suspense is an experimental feature subject to change in future versions.
7
+ */
8
+ suspend?: boolean;
9
+ suspendUntilReady?: never;
10
+ suspendWhileReconciling?: never;
11
+ } | {
12
+ /**
13
+ * Suspend flag evaluations while the provider is not ready.
14
+ * Set to false if you don't want to show suspense fallbacks until the provider is initialized.
15
+ * Defaults to false.
16
+ * Cannot be used in conjunction with `suspend` option.
17
+ * @experimental Suspense is an experimental feature subject to change in future versions.
18
+ */
19
+ suspendUntilReady?: boolean;
20
+ /**
21
+ * Suspend flag evaluations while the provider's context is being reconciled.
22
+ * Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.
23
+ * Defaults to false.
24
+ * Cannot be used in conjunction with `suspend` option.
25
+ * @experimental Suspense is an experimental feature subject to change in future versions.
26
+ */
27
+ suspendWhileReconciling?: boolean;
28
+ suspend?: never;
29
+ }) & {
30
+ /**
31
+ * Update the component if the provider emits a ConfigurationChanged event.
32
+ * Set to false to prevent components from re-rendering when flag value changes
33
+ * are received by the associated provider.
34
+ * Defaults to true.
35
+ */
36
+ updateOnConfigurationChanged?: boolean;
37
+ /**
38
+ * Update the component when the OpenFeature context changes.
39
+ * Set to false to prevent components from re-rendering when attributes which
40
+ * may be factors in flag evaluation change.
41
+ * Defaults to true.
42
+ */
43
+ updateOnContextChanged?: boolean;
44
+ } & FlagEvaluationOptions;
45
+ export type ReactFlagEvaluationNoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>;
46
+ export type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>;
@@ -0,0 +1,5 @@
1
+ export * from './provider';
2
+ export * from './use-open-feature-client';
3
+ export * from './use-when-provider-ready';
4
+ export * from './use-open-feature-client-status';
5
+ export * from './test-provider';
@@ -0,0 +1,27 @@
1
+ import type { Client } from '../sdk';
2
+ import * as React from 'react';
3
+ import type { ReactFlagEvaluationOptions } from '../options';
4
+ type ClientOrDomain = {
5
+ /**
6
+ * An identifier which logically binds clients with providers
7
+ * @see OpenFeature.setProvider() and overloads.
8
+ */
9
+ domain?: string;
10
+ client?: never;
11
+ } | {
12
+ /**
13
+ * OpenFeature client to use.
14
+ */
15
+ client?: Client;
16
+ domain?: never;
17
+ };
18
+ type ProviderProps = {
19
+ children?: React.ReactNode;
20
+ } & ClientOrDomain & ReactFlagEvaluationOptions;
21
+ /**
22
+ * Provides a scope for evaluating feature flags by binding a client to all child components.
23
+ * @param {ProviderProps} properties props for the context provider
24
+ * @returns {OpenFeatureProvider} context provider
25
+ */
26
+ export declare function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps): React.JSX.Element;
27
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { JsonValue, Provider } from '../sdk';
2
+ import React from 'react';
3
+ import { OpenFeatureProvider } from './provider';
4
+ type FlagValueMap = {
5
+ [flagKey: string]: JsonValue;
6
+ };
7
+ type TestProviderProps = Omit<React.ComponentProps<typeof OpenFeatureProvider>, 'client'> & ({
8
+ provider?: never;
9
+ /**
10
+ * Optional map of flagKeys to flagValues for this OpenFeatureTestProvider context.
11
+ * If not supplied, all flag evaluations will default.
12
+ */
13
+ flagValueMap?: FlagValueMap;
14
+ /**
15
+ * Optional delay for the underlying test provider's readiness and reconciliation.
16
+ * Defaults to 0.
17
+ */
18
+ delayMs?: number;
19
+ } | {
20
+ /**
21
+ * An optional partial provider to pass for full control over the flag resolution for this OpenFeatureTestProvider context.
22
+ * Any un-implemented methods or properties will no-op.
23
+ */
24
+ provider?: Partial<Provider>;
25
+ flagValueMap?: never;
26
+ delayMs?: never;
27
+ });
28
+ /**
29
+ * A React Context provider based on the {@link TypedInMemoryProvider}, specifically built for testing.
30
+ * Use this for testing components that use flag evaluation hooks.
31
+ * @param {TestProviderProps} testProviderOptions options for the OpenFeatureTestProvider
32
+ * @returns {OpenFeatureProvider} OpenFeatureTestProvider
33
+ */
34
+ export declare function OpenFeatureTestProvider(testProviderOptions: TestProviderProps): React.JSX.Element;
35
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ProviderStatus } from '../sdk';
2
+ /**
3
+ * Get the {@link ProviderStatus} for the OpenFeatureClient.
4
+ * Reacts to changes in provider status.
5
+ * @returns {ProviderStatus} status of the client for this scope
6
+ */
7
+ export declare function useOpenFeatureClientStatus(): ProviderStatus;
@@ -0,0 +1,7 @@
1
+ import { type Client } from '../sdk';
2
+ /**
3
+ * Get the {@link Client} instance for this OpenFeatureProvider context.
4
+ * Note that the provider to which this is bound is determined by the OpenFeatureProvider's domain.
5
+ * @returns {Client} client for this scope
6
+ */
7
+ export declare function useOpenFeatureClient(): Client;
@@ -0,0 +1,8 @@
1
+ import type { Provider } from '../sdk';
2
+ /**
3
+ * Get the {@link Provider} bound to the domain specified in the OpenFeatureProvider context.
4
+ * Note that it isn't recommended to interact with the provider directly, but rather through
5
+ * an OpenFeature client.
6
+ * @returns {Provider} provider for this scope
7
+ */
8
+ export declare function useOpenFeatureProvider(): Provider;
@@ -0,0 +1,14 @@
1
+ import type { ReactFlagEvaluationOptions } from '../options';
2
+ type Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;
3
+ /**
4
+ * Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.
5
+ * Especially useful for React v16/17 "Legacy Suspense", in which siblings to suspending components are
6
+ * initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).
7
+ *
8
+ * NOTE: This hook returns true only when the provider status is {@link ProviderStatus.READY}.
9
+ * For other statuses (ERROR, STALE, FATAL, RECONCILING), use {@link useOpenFeatureClientStatus}.
10
+ * @param {Options} options options for suspense
11
+ * @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own
12
+ */
13
+ export declare function useWhenProviderReady(options?: Options): boolean;
14
+ export {};
@@ -0,0 +1 @@
1
+ export * from './query';
@@ -0,0 +1,48 @@
1
+ import type { ErrorCode, EvaluationDetails, FlagMetadata, FlagValue, StandardResolutionReasons } from '../sdk';
2
+ export interface FlagQuery<T extends FlagValue = FlagValue> {
3
+ /**
4
+ * A structure representing the result of the flag evaluation process
5
+ */
6
+ readonly details: EvaluationDetails<T>;
7
+ /**
8
+ * The flag value
9
+ */
10
+ readonly value: T;
11
+ /**
12
+ * A variant is a semantic identifier for a value.
13
+ * Not available from all providers.
14
+ */
15
+ readonly variant: string | undefined;
16
+ /**
17
+ * Arbitrary data associated with this flag or evaluation.
18
+ * Not available from all providers.
19
+ */
20
+ readonly flagMetadata: FlagMetadata;
21
+ /**
22
+ * The reason the evaluation resolved to the particular value.
23
+ * Not available from all providers.
24
+ */
25
+ readonly reason: typeof StandardResolutionReasons | string | undefined;
26
+ /**
27
+ * Indicates if this flag defaulted due to an error.
28
+ * Specifically, indicates reason equals {@link StandardResolutionReasons.ERROR} or the errorCode is set, this field is truthy.
29
+ */
30
+ readonly isError: boolean;
31
+ /**
32
+ * The error code, see {@link ErrorCode}.
33
+ */
34
+ readonly errorCode: ErrorCode | undefined;
35
+ /**
36
+ * A message associated with the error.
37
+ */
38
+ readonly errorMessage: string | undefined;
39
+ /**
40
+ * Indicates this flag is up-to-date and in sync with the source of truth.
41
+ * Specifically, indicates the evaluation did not default due to error, and the reason is neither {@link StandardResolutionReasons.STALE} or {@link StandardResolutionReasons.DISABLED}.
42
+ */
43
+ readonly isAuthoritative: boolean;
44
+ /**
45
+ * The type of the value, as returned by "typeof" operator.
46
+ */
47
+ readonly type: 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
48
+ }
@@ -0,0 +1,43 @@
1
+ import { ProviderStatus, type Client, type EvaluationContext, type Hook, type Provider } from './types';
2
+ /**
3
+ * The OpenFeature singleton. One provider + one evaluation context per **domain**;
4
+ * the default provider / context serve every domain that has none of its own.
5
+ */
6
+ export declare class OpenFeatureAPI {
7
+ private _defaultProvider;
8
+ private _domainProviders;
9
+ private _context;
10
+ private _domainContext;
11
+ private _emitters;
12
+ private _hooks;
13
+ static getInstance(): OpenFeatureAPI;
14
+ /** Sync version: errors during init are logged, status tells the rest. */
15
+ setProvider(provider: Provider): this;
16
+ setProvider(provider: Provider, context: EvaluationContext): this;
17
+ setProvider(domain: string, provider: Provider): this;
18
+ setProvider(domain: string, provider: Provider, context: EvaluationContext): this;
19
+ /** Resolves when the provider is READY (rejects if its initialize() fails). */
20
+ setProviderAndWait(provider: Provider): Promise<void>;
21
+ setProviderAndWait(provider: Provider, context: EvaluationContext): Promise<void>;
22
+ setProviderAndWait(domain: string, provider: Provider): Promise<void>;
23
+ setProviderAndWait(domain: string, provider: Provider, context: EvaluationContext): Promise<void>;
24
+ private set;
25
+ getProvider(domain?: string): Provider;
26
+ getProviderStatus(domain?: string): ProviderStatus;
27
+ private wrapperFor;
28
+ clearProviders(): Promise<void>;
29
+ getContext(domain?: string): EvaluationContext;
30
+ /** Set the global context (domain omitted) or one domain's context. Providers get `onContextChange`; clients get `ContextChanged`. */
31
+ setContext(context: EvaluationContext): Promise<void>;
32
+ setContext(domain: string, context: EvaluationContext): Promise<void>;
33
+ clearContext(domain?: string): Promise<void>;
34
+ private contextChanged;
35
+ getClient(domain?: string, version?: string): Client;
36
+ addHooks(...hooks: Hook[]): this;
37
+ clearHooks(): this;
38
+ getHooks(): Hook[];
39
+ private emitterOf;
40
+ /** Events of the default provider also reach domains that have no provider of their own. */
41
+ private emit;
42
+ }
43
+ export declare const OpenFeature: OpenFeatureAPI;