@shiva004/surveys 0.12.1 → 0.12.2
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/dist/elements.js +5582 -6061
- package/dist/flags/client/client.d.ts +34 -0
- package/dist/flags/client/context.d.ts +19 -0
- package/dist/flags/client/events.d.ts +18 -0
- package/dist/flags/client/index.d.ts +4 -0
- package/dist/flags/client/status.d.ts +17 -0
- package/dist/flags/client/types.d.ts +77 -0
- package/dist/{openfeature → flags}/context/use-context-mutator.d.ts +6 -6
- package/dist/flags/declarative/FeatureFlag.d.ts +52 -0
- package/dist/flags/evaluation/use-feature-flag.d.ts +43 -0
- package/dist/{openfeature → flags}/internal/context.d.ts +3 -3
- package/dist/flags/internal/hook-flag-query.d.ts +16 -0
- package/dist/flags/internal/suspense.d.ts +18 -0
- package/dist/{openfeature → flags}/internal/use.d.ts +1 -2
- package/dist/{openfeature → flags}/options.d.ts +6 -9
- package/dist/flags/provider/index.d.ts +5 -0
- package/dist/{openfeature → flags}/provider/provider.d.ts +7 -7
- package/dist/flags/provider/use-flags-backend.d.ts +8 -0
- package/dist/flags/provider/use-flags-client-status.d.ts +7 -0
- package/dist/flags/provider/use-flags-client.d.ts +7 -0
- package/dist/flags/provider/use-when-flags-ready.d.ts +13 -0
- package/dist/{openfeature → flags}/query/query.d.ts +7 -10
- package/dist/{openfeature/index.d.ts → flags/sdk.d.ts} +1 -1
- package/dist/{openfeature → flags}/tracking/use-track.d.ts +4 -3
- package/dist/index.d.ts +1 -4
- package/dist/index.js +5212 -5691
- package/package.json +8 -5
- package/dist/flags/OpenFeatureFlags.d.ts +0 -21
- package/dist/flags/openfeature.d.ts +0 -36
- package/dist/openfeature/declarative/FeatureFlag.d.ts +0 -68
- package/dist/openfeature/evaluation/use-feature-flag.d.ts +0 -113
- package/dist/openfeature/internal/hook-flag-query.d.ts +0 -16
- package/dist/openfeature/internal/suspense.d.ts +0 -18
- package/dist/openfeature/provider/index.d.ts +0 -5
- package/dist/openfeature/provider/test-provider.d.ts +0 -35
- package/dist/openfeature/provider/use-open-feature-client-status.d.ts +0 -7
- package/dist/openfeature/provider/use-open-feature-client.d.ts +0 -7
- package/dist/openfeature/provider/use-open-feature-provider.d.ts +0 -8
- package/dist/openfeature/provider/use-when-provider-ready.d.ts +0 -14
- package/dist/openfeature/sdk/api.d.ts +0 -43
- package/dist/openfeature/sdk/client.d.ts +0 -46
- package/dist/openfeature/sdk/errors.d.ts +0 -38
- package/dist/openfeature/sdk/events.d.ts +0 -10
- package/dist/openfeature/sdk/index.d.ts +0 -8
- package/dist/openfeature/sdk/providers.d.ts +0 -46
- package/dist/openfeature/sdk/types.d.ts +0 -168
- /package/dist/{openfeature → flags}/context/index.d.ts +0 -0
- /package/dist/{openfeature → flags}/declarative/index.d.ts +0 -0
- /package/dist/{openfeature → flags}/evaluation/index.d.ts +0 -0
- /package/dist/{openfeature → flags}/internal/errors.d.ts +0 -0
- /package/dist/{openfeature → flags}/internal/index.d.ts +0 -0
- /package/dist/{openfeature → flags}/internal/is-equal.d.ts +0 -0
- /package/dist/{openfeature → flags}/internal/options.d.ts +0 -0
- /package/dist/{openfeature → flags}/query/index.d.ts +0 -0
- /package/dist/{openfeature → flags}/tracking/index.d.ts +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ProviderEvents, ProviderStatus, type EvaluationContext, type EvaluationDetails, type EventHandler, type FlagEvaluationOptions, type TrackingEventDetails } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The thing a client evaluates against. In OpenFeature this is a "provider"; here it is the local store in ./data
|
|
4
|
+
* (optionally synced with your backend through connectFlags). Used as a key for suspense.
|
|
5
|
+
*/
|
|
6
|
+
export declare const flagsBackend: {
|
|
7
|
+
readonly metadata: {
|
|
8
|
+
readonly name: "user-journey-flags";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type FlagsBackend = typeof flagsBackend;
|
|
12
|
+
export interface FlagsClient {
|
|
13
|
+
/** The domain this client is bound to (its own evaluation context), if any. */
|
|
14
|
+
readonly metadata: {
|
|
15
|
+
readonly domain?: string;
|
|
16
|
+
};
|
|
17
|
+
readonly providerStatus: ProviderStatus;
|
|
18
|
+
/** The evaluation context this client evaluates with. */
|
|
19
|
+
getContext(): EvaluationContext;
|
|
20
|
+
getBooleanValue(flagKey: string, defaultValue: boolean, options?: FlagEvaluationOptions): boolean;
|
|
21
|
+
getBooleanDetails(flagKey: string, defaultValue: boolean, options?: FlagEvaluationOptions): EvaluationDetails<boolean>;
|
|
22
|
+
/** Listen to provider events. Pass an AbortSignal to remove the handler. */
|
|
23
|
+
addHandler(event: ProviderEvents, handler: EventHandler, options?: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): void;
|
|
26
|
+
/** Track a business event (conversion, purchase...) tied to the current user. */
|
|
27
|
+
track(trackingEventName: string, trackingEventDetails?: TrackingEventDetails): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a client. Evaluations use the default evaluation context, or the context of `domain` when one is given.
|
|
31
|
+
* @param {string} domain optional domain name
|
|
32
|
+
* @returns {FlagsClient} a client bound to that domain
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFlagsClient(domain?: string): FlagsClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EvaluationContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get the evaluation context for a domain. A domain without its own context uses the default context.
|
|
4
|
+
* @param {string} domain optional domain name
|
|
5
|
+
* @returns {EvaluationContext} the current context
|
|
6
|
+
*/
|
|
7
|
+
export declare function getContext(domain?: string): EvaluationContext;
|
|
8
|
+
/**
|
|
9
|
+
* Set the default context, or the context of one domain.
|
|
10
|
+
* Components that evaluate flags re-render when this resolves.
|
|
11
|
+
* @param {EvaluationContext} context the new default context
|
|
12
|
+
*/
|
|
13
|
+
export declare function setContext(context: EvaluationContext): Promise<void>;
|
|
14
|
+
export declare function setContext(domain: string, context: EvaluationContext): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Remove the context of a domain (or reset the default context to empty).
|
|
17
|
+
* @param {string} domain optional domain name
|
|
18
|
+
*/
|
|
19
|
+
export declare function clearContext(domain?: string): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EventDetails, EventHandler, ProviderEvents } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Register a handler for a provider event. Pass an AbortSignal to remove it again.
|
|
4
|
+
* @param {ProviderEvents} event the event to listen to
|
|
5
|
+
* @param {EventHandler} handler called with the event details
|
|
6
|
+
* @param {{ signal?: AbortSignal }} options pass `signal` to unregister the handler when it aborts
|
|
7
|
+
*/
|
|
8
|
+
export declare function addHandler(event: ProviderEvents, handler: EventHandler, options?: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}): void;
|
|
11
|
+
/**
|
|
12
|
+
* Emit an event to every handler. A throwing handler never breaks the others.
|
|
13
|
+
* **DO NOT EXPORT PUBLICLY**
|
|
14
|
+
* @internal
|
|
15
|
+
* @param {ProviderEvents} event the event to emit
|
|
16
|
+
* @param {EventDetails} details details passed to each handler
|
|
17
|
+
*/
|
|
18
|
+
export declare function emitEvent(event: ProviderEvents, details?: EventDetails): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProviderStatus } from './types';
|
|
2
|
+
/** **DO NOT EXPORT PUBLICLY** @internal */
|
|
3
|
+
export declare const beginReconcile: () => void;
|
|
4
|
+
/** **DO NOT EXPORT PUBLICLY** @internal */
|
|
5
|
+
export declare const endReconcile: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Status of the flag source. Without `connectFlags` the local store is always READY;
|
|
8
|
+
* with it, the status follows the backend connection.
|
|
9
|
+
* @returns {ProviderStatus} the current status
|
|
10
|
+
*/
|
|
11
|
+
export declare function getProviderStatus(): ProviderStatus;
|
|
12
|
+
/**
|
|
13
|
+
* Connect the framework-free store (./data) to provider events. Safe to call many times.
|
|
14
|
+
* **DO NOT EXPORT PUBLICLY**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function wireStore(): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Env } from '../data';
|
|
2
|
+
/** The only flag type this store has: on / off. The generic parameters elsewhere are kept so more types can be added later. */
|
|
3
|
+
export type FlagValue = boolean;
|
|
4
|
+
export type FlagMetadata = Record<string, string | number | boolean>;
|
|
5
|
+
export type EvaluationContextValue = string | number | boolean | null | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* What your app knows about the current user, e.g. `{ targetingKey: 'u_42', country: 'IN', plan: 'pro' }`.
|
|
8
|
+
* `targetingKey` is the user id used for rollout bucketing; every other key is a user attribute used by targeting rules.
|
|
9
|
+
*/
|
|
10
|
+
export type EvaluationContext = {
|
|
11
|
+
targetingKey?: string;
|
|
12
|
+
} & Record<string, EvaluationContextValue>;
|
|
13
|
+
export declare const StandardResolutionReasons: {
|
|
14
|
+
/** The flag has a fixed value (on for everyone). */
|
|
15
|
+
readonly STATIC: "STATIC";
|
|
16
|
+
/** The value is the caller's default. */
|
|
17
|
+
readonly DEFAULT: "DEFAULT";
|
|
18
|
+
/** A targeting rule decided. */
|
|
19
|
+
readonly TARGETING_MATCH: "TARGETING_MATCH";
|
|
20
|
+
/** The user fell in (or out of) a percentage rollout. */
|
|
21
|
+
readonly SPLIT: "SPLIT";
|
|
22
|
+
/** The flag is off in this environment, archived or a draft. */
|
|
23
|
+
readonly DISABLED: "DISABLED";
|
|
24
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
25
|
+
/** The value comes from a connection that is out of date. */
|
|
26
|
+
readonly STALE: "STALE";
|
|
27
|
+
readonly ERROR: "ERROR";
|
|
28
|
+
};
|
|
29
|
+
export type ResolutionReason = (typeof StandardResolutionReasons)[keyof typeof StandardResolutionReasons];
|
|
30
|
+
export declare const ErrorCode: {
|
|
31
|
+
readonly PROVIDER_NOT_READY: "PROVIDER_NOT_READY";
|
|
32
|
+
readonly FLAG_NOT_FOUND: "FLAG_NOT_FOUND";
|
|
33
|
+
readonly GENERAL: "GENERAL";
|
|
34
|
+
};
|
|
35
|
+
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
36
|
+
/** The result of one evaluation. */
|
|
37
|
+
export interface EvaluationDetails<T extends FlagValue = FlagValue> {
|
|
38
|
+
flagKey: string;
|
|
39
|
+
value: T;
|
|
40
|
+
/** `on` or `off`. */
|
|
41
|
+
variant?: string;
|
|
42
|
+
reason?: ResolutionReason;
|
|
43
|
+
flagMetadata: FlagMetadata;
|
|
44
|
+
errorCode?: ErrorCode;
|
|
45
|
+
errorMessage?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface FlagEvaluationOptions {
|
|
48
|
+
/** Environment to evaluate in. Default: the environment set with `configureFlags({ environment })`. */
|
|
49
|
+
env?: Env;
|
|
50
|
+
}
|
|
51
|
+
export declare const ProviderStatus: {
|
|
52
|
+
readonly NOT_READY: "NOT_READY";
|
|
53
|
+
readonly READY: "READY";
|
|
54
|
+
readonly ERROR: "ERROR";
|
|
55
|
+
readonly STALE: "STALE";
|
|
56
|
+
readonly RECONCILING: "RECONCILING";
|
|
57
|
+
};
|
|
58
|
+
export type ProviderStatus = (typeof ProviderStatus)[keyof typeof ProviderStatus];
|
|
59
|
+
export declare const ProviderEvents: {
|
|
60
|
+
readonly Ready: "PROVIDER_READY";
|
|
61
|
+
readonly Error: "PROVIDER_ERROR";
|
|
62
|
+
readonly Stale: "PROVIDER_STALE";
|
|
63
|
+
readonly ConfigurationChanged: "PROVIDER_CONFIGURATION_CHANGED";
|
|
64
|
+
readonly ContextChanged: "PROVIDER_CONTEXT_CHANGED";
|
|
65
|
+
readonly Reconciling: "PROVIDER_RECONCILING";
|
|
66
|
+
};
|
|
67
|
+
export type ProviderEvents = (typeof ProviderEvents)[keyof typeof ProviderEvents];
|
|
68
|
+
export interface EventDetails {
|
|
69
|
+
/** Keys of the flags that changed (ConfigurationChanged only). When missing, assume every flag may have changed. */
|
|
70
|
+
flagsChanged?: string[];
|
|
71
|
+
/** The domain whose context changed (ContextChanged only). `undefined` means the default context. */
|
|
72
|
+
domain?: string;
|
|
73
|
+
message?: string;
|
|
74
|
+
}
|
|
75
|
+
export type EventHandler = (details?: EventDetails) => void;
|
|
76
|
+
/** Details attached to a tracked business event (conversion, purchase, ...). */
|
|
77
|
+
export type TrackingEventDetails = Record<string, unknown>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EvaluationContext } from '../client';
|
|
2
2
|
export type ContextMutationOptions = {
|
|
3
3
|
/**
|
|
4
|
-
* Mutate the default context instead of the domain scoped context applied at the `<
|
|
5
|
-
* By default, will use the domain set on `<
|
|
6
|
-
*
|
|
4
|
+
* Mutate the default context instead of the domain scoped context applied at the `<FlagsProvider/>`.
|
|
5
|
+
* By default, will use the domain set on `<FlagsProvider/>` (or the domain associated with the client set on `<FlagsProvider/>`).
|
|
6
|
+
* Without a domain, the default context is used either way.
|
|
7
7
|
* @default false
|
|
8
8
|
*/
|
|
9
9
|
defaultContext?: boolean;
|
|
@@ -19,8 +19,8 @@ export type ContextMutation = {
|
|
|
19
19
|
setContext: (updatedContext: EvaluationContext | ((currentContext: EvaluationContext) => EvaluationContext)) => Promise<void>;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* Get context-aware
|
|
23
|
-
*
|
|
22
|
+
* Get context-aware function(s) for mutating the evaluation context associated with this domain, or the default context if `defaultContext: true`.
|
|
23
|
+
* Use it to tell the flags who the user is, e.g. after login: `setContext({ targetingKey: user.id, country: 'IN', plan: 'pro' })`.
|
|
24
24
|
* @param {ContextMutationOptions} options options for the generated function
|
|
25
25
|
* @returns {ContextMutation} context-aware function(s) to mutate evaluation context
|
|
26
26
|
*/
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FlagQuery } from '../query';
|
|
3
|
+
import type { EvaluationDetails } from '../client';
|
|
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 {
|
|
10
|
+
/**
|
|
11
|
+
* The key of the feature flag to evaluate.
|
|
12
|
+
*/
|
|
13
|
+
flagKey: string;
|
|
14
|
+
/**
|
|
15
|
+
* Default value to use when the feature flag is not found or the flags are not ready.
|
|
16
|
+
*/
|
|
17
|
+
defaultValue: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Optional value to match against the feature flag value. When omitted, children render when the flag is on.
|
|
20
|
+
*/
|
|
21
|
+
matchValue?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Optional predicate function for custom matching logic.
|
|
24
|
+
* If provided, this function will be used instead of the default equality check.
|
|
25
|
+
* @param matchValue The value to match (matchValue prop)
|
|
26
|
+
* @param details The evaluation details
|
|
27
|
+
* @returns true if the condition is met, false otherwise
|
|
28
|
+
*/
|
|
29
|
+
predicate?: (matchValue: boolean | undefined, details: EvaluationDetails<boolean>) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Content to render when the feature flag condition is met.
|
|
32
|
+
* Can be a React node or a function that receives flag query details and returns a React node.
|
|
33
|
+
*/
|
|
34
|
+
children: React.ReactNode | ((details: FlagQuery<boolean>) => React.ReactNode);
|
|
35
|
+
/**
|
|
36
|
+
* Optional content to render when the feature flag condition is not met.
|
|
37
|
+
* Can be a React node or a function that receives evaluation details and returns a React node.
|
|
38
|
+
*/
|
|
39
|
+
fallback?: React.ReactNode | ((details: EvaluationDetails<boolean>) => React.ReactNode);
|
|
40
|
+
/**
|
|
41
|
+
* Flag evaluation options that will be passed to useFlag hook.
|
|
42
|
+
*/
|
|
43
|
+
evaluationOptions?: ReactFlagEvaluationOptions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* FeatureFlag component that conditionally renders its children based on the evaluation of a feature flag.
|
|
47
|
+
* @example <FeatureFlag flagKey="new_checkout_flow" defaultValue={false} fallback={<OldCheckout />}><NewCheckout /></FeatureFlag>
|
|
48
|
+
* @param {FeatureFlagProps} props The properties for the FeatureFlag component.
|
|
49
|
+
* @returns {React.ReactElement | null} The rendered component or null if the feature is not enabled.
|
|
50
|
+
*/
|
|
51
|
+
export declare function FeatureFlag({ flagKey, matchValue, predicate, defaultValue, children, evaluationOptions, fallback, }: FeatureFlagProps): React.ReactElement | null;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { EvaluationDetails } from '../client';
|
|
2
|
+
import type { ReactFlagEvaluationNoSuspenseOptions, ReactFlagEvaluationOptions } from '../options';
|
|
3
|
+
import type { FlagQuery } from '../query';
|
|
4
|
+
/**
|
|
5
|
+
* Evaluates a feature flag generically, returning a react-flavored queryable object.
|
|
6
|
+
* The resolver method to use is based on the type of the defaultValue (only booleans exist today).
|
|
7
|
+
* For type-specific hooks, use {@link useBooleanFlagValue}, {@link useBooleanFlagDetails}.
|
|
8
|
+
* By default, components will re-render when the flag value changes.
|
|
9
|
+
* @param {string} flagKey the flag identifier
|
|
10
|
+
* @param {boolean} defaultValue the default value; returned when the flag does not exist or flags are not ready.
|
|
11
|
+
* @param {ReactFlagEvaluationOptions} options for this evaluation
|
|
12
|
+
* @returns { FlagQuery } a queryable object containing useful information about the flag.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useFlag(flagKey: string, defaultValue: boolean, options?: ReactFlagEvaluationOptions): FlagQuery<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Equivalent to {@link useFlag} with `options: { suspend: true }`
|
|
17
|
+
* @experimental Suspense is an experimental feature subject to change in future versions.
|
|
18
|
+
* @param {string} flagKey the flag identifier
|
|
19
|
+
* @param {boolean} defaultValue the default value
|
|
20
|
+
* @param {ReactFlagEvaluationNoSuspenseOptions} options for this evaluation
|
|
21
|
+
* @returns { FlagQuery<boolean> } a queryable object containing useful information about the flag.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useSuspenseFlag(flagKey: string, defaultValue: boolean, options?: ReactFlagEvaluationNoSuspenseOptions): FlagQuery<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Evaluates a feature flag, returning a boolean.
|
|
26
|
+
* By default, components will re-render when the flag value changes.
|
|
27
|
+
* For a generic hook returning a queryable interface, see {@link useFlag}.
|
|
28
|
+
* @param {string} flagKey the flag identifier
|
|
29
|
+
* @param {boolean} defaultValue the default value
|
|
30
|
+
* @param {ReactFlagEvaluationOptions} options options for this evaluation
|
|
31
|
+
* @returns { boolean } the flag value
|
|
32
|
+
*/
|
|
33
|
+
export declare function useBooleanFlagValue(flagKey: string, defaultValue: boolean, options?: ReactFlagEvaluationOptions): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Evaluates a feature flag, returning evaluation details.
|
|
36
|
+
* By default, components will re-render when the flag value changes.
|
|
37
|
+
* For a generic hook returning a queryable interface, see {@link useFlag}.
|
|
38
|
+
* @param {string} flagKey the flag identifier
|
|
39
|
+
* @param {boolean} defaultValue the default value
|
|
40
|
+
* @param {ReactFlagEvaluationOptions} options options for this evaluation
|
|
41
|
+
* @returns { EvaluationDetails<boolean> } a EvaluationDetails object for this evaluation
|
|
42
|
+
*/
|
|
43
|
+
export declare function useBooleanFlagDetails(flagKey: string, defaultValue: boolean, options?: ReactFlagEvaluationOptions): EvaluationDetails<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Client } from '../sdk';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import type { FlagsClient } from '../client';
|
|
3
3
|
import type { NormalizedOptions, ReactFlagEvaluationOptions } from '../options';
|
|
4
4
|
/**
|
|
5
5
|
* The underlying React context.
|
|
@@ -8,11 +8,11 @@ import type { NormalizedOptions, ReactFlagEvaluationOptions } from '../options';
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export declare const Context: React.Context<{
|
|
11
|
-
client:
|
|
11
|
+
client: FlagsClient;
|
|
12
12
|
options: ReactFlagEvaluationOptions;
|
|
13
13
|
} | undefined>;
|
|
14
14
|
/**
|
|
15
|
-
* Get a normalized copy of the options used for this
|
|
15
|
+
* Get a normalized copy of the options used for this FlagsProvider, see {@link normalizeOptions}.
|
|
16
16
|
*
|
|
17
17
|
* **DO NOT EXPORT PUBLICLY**
|
|
18
18
|
* @internal
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EvaluationDetails, FlagValue } from '../client';
|
|
2
|
+
import type { FlagQuery } from '../query';
|
|
3
|
+
export declare class HookFlagQuery<T extends FlagValue = FlagValue> implements FlagQuery<T> {
|
|
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(): import("../client").FlagMetadata;
|
|
10
|
+
get reason(): import("../client").ResolutionReason | undefined;
|
|
11
|
+
get isError(): boolean;
|
|
12
|
+
get errorCode(): import("../client").ErrorCode | undefined;
|
|
13
|
+
get errorMessage(): string | undefined;
|
|
14
|
+
get isAuthoritative(): boolean;
|
|
15
|
+
get type(): "boolean";
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FlagsBackend, type FlagsClient } from '../client';
|
|
2
|
+
/**
|
|
3
|
+
* Suspends until the client is ready to evaluate feature flags.
|
|
4
|
+
*
|
|
5
|
+
* **DO NOT EXPORT PUBLICLY**
|
|
6
|
+
* @internal
|
|
7
|
+
* @param {FlagsBackend} backend the backend to suspend for
|
|
8
|
+
* @param {FlagsClient} client the client to check for readiness
|
|
9
|
+
*/
|
|
10
|
+
export declare function suspendUntilInitialized(backend: FlagsBackend, client: FlagsClient): void;
|
|
11
|
+
/**
|
|
12
|
+
* Suspends until the context has finished reconciling.
|
|
13
|
+
*
|
|
14
|
+
* **DO NOT EXPORT PUBLICLY**
|
|
15
|
+
* @internal
|
|
16
|
+
* @param {FlagsClient} client the client to check for readiness
|
|
17
|
+
*/
|
|
18
|
+
export declare function suspendUntilReconciled(client: FlagsClient): void;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
/**
|
|
3
2
|
* Extends a Promise-like value to include status tracking.
|
|
4
3
|
* The extra properties are used to manage the lifecycle of the Promise, indicating its current state.
|
|
@@ -16,4 +15,4 @@ export type UsePromise<T> = Promise<T> & {
|
|
|
16
15
|
* @param {UsePromise} thenable A thenable object that represents a Promise-like value.
|
|
17
16
|
* @returns {unknown} The resolved value of the thenable or throws if it's still pending or rejected.
|
|
18
17
|
*/
|
|
19
|
-
export declare const use:
|
|
18
|
+
export declare const use: <T>(thenable: UsePromise<T>) => T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FlagEvaluationOptions } from './
|
|
1
|
+
import type { FlagEvaluationOptions } from './client';
|
|
2
2
|
export type ReactFlagEvaluationOptions = ({
|
|
3
3
|
/**
|
|
4
4
|
* Enable or disable all suspense functionality.
|
|
@@ -10,16 +10,14 @@ export type ReactFlagEvaluationOptions = ({
|
|
|
10
10
|
suspendWhileReconciling?: never;
|
|
11
11
|
} | {
|
|
12
12
|
/**
|
|
13
|
-
* Suspend flag evaluations while the
|
|
14
|
-
* Set to false if you don't want to show suspense fallbacks until the provider is initialized.
|
|
13
|
+
* Suspend flag evaluations while the flags are not ready (loading from your backend).
|
|
15
14
|
* Defaults to false.
|
|
16
15
|
* Cannot be used in conjunction with `suspend` option.
|
|
17
16
|
* @experimental Suspense is an experimental feature subject to change in future versions.
|
|
18
17
|
*/
|
|
19
18
|
suspendUntilReady?: boolean;
|
|
20
19
|
/**
|
|
21
|
-
* Suspend flag evaluations while the
|
|
22
|
-
* Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes.
|
|
20
|
+
* Suspend flag evaluations while the evaluation context is being reconciled.
|
|
23
21
|
* Defaults to false.
|
|
24
22
|
* Cannot be used in conjunction with `suspend` option.
|
|
25
23
|
* @experimental Suspense is an experimental feature subject to change in future versions.
|
|
@@ -28,14 +26,13 @@ export type ReactFlagEvaluationOptions = ({
|
|
|
28
26
|
suspend?: never;
|
|
29
27
|
}) & {
|
|
30
28
|
/**
|
|
31
|
-
* Update the component if
|
|
32
|
-
* Set to false to prevent components from re-rendering when flag
|
|
33
|
-
* are received by the associated provider.
|
|
29
|
+
* Update the component if a flag changes (toggle, rollout, rule, backend sync).
|
|
30
|
+
* Set to false to prevent components from re-rendering when flag changes are received.
|
|
34
31
|
* Defaults to true.
|
|
35
32
|
*/
|
|
36
33
|
updateOnConfigurationChanged?: boolean;
|
|
37
34
|
/**
|
|
38
|
-
* Update the component when the
|
|
35
|
+
* Update the component when the evaluation context changes.
|
|
39
36
|
* Set to false to prevent components from re-rendering when attributes which
|
|
40
37
|
* may be factors in flag evaluation change.
|
|
41
38
|
* Defaults to true.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { Client } from '../sdk';
|
|
2
1
|
import * as React from 'react';
|
|
2
|
+
import { type FlagsClient } from '../client';
|
|
3
3
|
import type { ReactFlagEvaluationOptions } from '../options';
|
|
4
4
|
type ClientOrDomain = {
|
|
5
5
|
/**
|
|
6
|
-
* An identifier which
|
|
7
|
-
* @see
|
|
6
|
+
* An identifier which gives this part of the app its own evaluation context (see `useContextMutator`).
|
|
7
|
+
* @see getFlagsClient()
|
|
8
8
|
*/
|
|
9
9
|
domain?: string;
|
|
10
10
|
client?: never;
|
|
11
11
|
} | {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Flags client to use.
|
|
14
14
|
*/
|
|
15
|
-
client?:
|
|
15
|
+
client?: FlagsClient;
|
|
16
16
|
domain?: never;
|
|
17
17
|
};
|
|
18
18
|
type ProviderProps = {
|
|
@@ -21,7 +21,7 @@ type ProviderProps = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Provides a scope for evaluating feature flags by binding a client to all child components.
|
|
23
23
|
* @param {ProviderProps} properties props for the context provider
|
|
24
|
-
* @returns {
|
|
24
|
+
* @returns {FlagsProvider} context provider
|
|
25
25
|
*/
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function FlagsProvider({ client, domain, children, ...options }: ProviderProps): React.JSX.Element;
|
|
27
27
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FlagsBackend } from '../client';
|
|
2
|
+
/**
|
|
3
|
+
* Get the {@link FlagsBackend} (the local store, optionally synced with your API) used in the FlagsProvider context.
|
|
4
|
+
* Note that it isn't recommended to interact with the backend directly, but rather through
|
|
5
|
+
* a flags client.
|
|
6
|
+
* @returns {FlagsBackend} backend for this scope
|
|
7
|
+
*/
|
|
8
|
+
export declare function useFlagsBackend(): FlagsBackend;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ProviderStatus } from '../client';
|
|
2
|
+
/**
|
|
3
|
+
* Get the {@link ProviderStatus} for the flags client.
|
|
4
|
+
* Reacts to changes in the status (backend connecting, ready, error).
|
|
5
|
+
* @returns {ProviderStatus} status of the client for this scope
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFlagsClientStatus(): ProviderStatus;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FlagsClient } from '../client';
|
|
2
|
+
/**
|
|
3
|
+
* Get the {@link FlagsClient} instance for this FlagsProvider context.
|
|
4
|
+
* Note that the evaluation context is determined by the FlagsProvider's domain.
|
|
5
|
+
* @returns {FlagsClient} client for this scope
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFlagsClient(): FlagsClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactFlagEvaluationOptions } from '../options';
|
|
2
|
+
type Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;
|
|
3
|
+
/**
|
|
4
|
+
* Utility hook that triggers suspense until the flags are {@link ProviderStatus.READY}, without evaluating any flags.
|
|
5
|
+
* Useful when flags are loaded from your backend with `connectFlags`.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This hook returns true only when the status is {@link ProviderStatus.READY}.
|
|
8
|
+
* For other statuses (ERROR, STALE, RECONCILING), use {@link useFlagsClientStatus}.
|
|
9
|
+
* @param {Options} options options for suspense
|
|
10
|
+
* @returns {boolean} boolean indicating if the flags are {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own
|
|
11
|
+
*/
|
|
12
|
+
export declare function useWhenFlagsReady(options?: Options): boolean;
|
|
13
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ErrorCode, EvaluationDetails, FlagMetadata, FlagValue,
|
|
1
|
+
import type { ErrorCode, EvaluationDetails, FlagMetadata, FlagValue, ResolutionReason } from '../client';
|
|
2
2
|
export interface FlagQuery<T extends FlagValue = FlagValue> {
|
|
3
3
|
/**
|
|
4
4
|
* A structure representing the result of the flag evaluation process
|
|
@@ -9,23 +9,20 @@ export interface FlagQuery<T extends FlagValue = FlagValue> {
|
|
|
9
9
|
*/
|
|
10
10
|
readonly value: T;
|
|
11
11
|
/**
|
|
12
|
-
* A variant is a semantic identifier for a value.
|
|
13
|
-
* Not available from all providers.
|
|
12
|
+
* A variant is a semantic identifier for a value (`on` or `off`).
|
|
14
13
|
*/
|
|
15
14
|
readonly variant: string | undefined;
|
|
16
15
|
/**
|
|
17
|
-
* Arbitrary data associated with this flag
|
|
18
|
-
* Not available from all providers.
|
|
16
|
+
* Arbitrary data associated with this evaluation: bucket, rule name, flag kind and a plain-text explanation.
|
|
19
17
|
*/
|
|
20
18
|
readonly flagMetadata: FlagMetadata;
|
|
21
19
|
/**
|
|
22
20
|
* The reason the evaluation resolved to the particular value.
|
|
23
|
-
* Not available from all providers.
|
|
24
21
|
*/
|
|
25
|
-
readonly reason:
|
|
22
|
+
readonly reason: ResolutionReason | undefined;
|
|
26
23
|
/**
|
|
27
24
|
* Indicates if this flag defaulted due to an error.
|
|
28
|
-
* Specifically, indicates reason equals
|
|
25
|
+
* Specifically, indicates reason equals ERROR or the errorCode is set, this field is truthy.
|
|
29
26
|
*/
|
|
30
27
|
readonly isError: boolean;
|
|
31
28
|
/**
|
|
@@ -38,11 +35,11 @@ export interface FlagQuery<T extends FlagValue = FlagValue> {
|
|
|
38
35
|
readonly errorMessage: string | undefined;
|
|
39
36
|
/**
|
|
40
37
|
* 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
|
|
38
|
+
* Specifically, indicates the evaluation did not default due to error, and the reason is neither STALE or DISABLED.
|
|
42
39
|
*/
|
|
43
40
|
readonly isAuthoritative: boolean;
|
|
44
41
|
/**
|
|
45
42
|
* The type of the value, as returned by "typeof" operator.
|
|
46
43
|
*/
|
|
47
|
-
readonly type: '
|
|
44
|
+
readonly type: 'boolean';
|
|
48
45
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TrackingEventDetails } from '../client';
|
|
2
2
|
export type Track = {
|
|
3
3
|
/**
|
|
4
|
-
* Context-aware tracking function for the parent `<
|
|
4
|
+
* Context-aware tracking function for the parent `<FlagsProvider/>`.
|
|
5
5
|
* Track a user action or application state, usually representing a business objective or outcome.
|
|
6
|
+
* The event reaches Live Events with source "flags".
|
|
6
7
|
* @param trackingEventName an identifier for the event
|
|
7
8
|
* @param trackingEventDetails the details of the tracking event
|
|
8
9
|
*/
|
|
9
|
-
track:
|
|
10
|
+
track: (trackingEventName: string, trackingEventDetails?: TrackingEventDetails) => void;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Get a context-aware tracking function.
|
package/dist/index.d.ts
CHANGED
|
@@ -20,11 +20,8 @@ export { configureFlags, isFeatureEnabled, evaluate as evaluateFlag, useFlags, g
|
|
|
20
20
|
export type { Flag, FlagKind, FlagsConfig, FlagsConnection, LiveStatus as FlagsLiveStatus, EnvState as FlagEnvState, Evaluation as FlagEvaluation, Env as FlagEnv } from './flags/data';
|
|
21
21
|
export { useTargeting, getSegments, getSegment, saveSegment, addAttribute as addUserAttribute, BUILTIN_ATTRIBUTES as USER_ATTRIBUTES, demoSegments, } from './flags/targeting';
|
|
22
22
|
export { deleteSegment, deleteAttribute } from './flags/data';
|
|
23
|
-
export { FlagsOpenFeatureProvider } from './flags/OpenFeatureFlags';
|
|
24
|
-
export type { FlagsOpenFeatureProviderProps } from './flags/OpenFeatureFlags';
|
|
25
|
-
export { FlagsProvider, FLAGS_DOMAIN, registerFlagsProvider, unregisterFlagsProvider, identifyFlagUser } from './flags/openfeature';
|
|
26
23
|
export { subscribeFlags } from './flags/data';
|
|
27
|
-
export * from './
|
|
24
|
+
export * from './flags/sdk';
|
|
28
25
|
export type { Segment, Rule as FlagRule, Condition as FlagCondition, Attribute as UserAttribute, Context as FlagContext } from './flags/targeting';
|
|
29
26
|
export { QueuesApp } from './queues/QueuesApp';
|
|
30
27
|
export type { QueuesAppProps } from './queues/QueuesApp';
|