@bluealba/pae-ui-react-core 4.0.1-feature-menu-display-order-1213 → 4.0.1-feature-initial-feature-flags-poc-1242
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/index.cjs.js +50 -50
- package/dist/index.esm.js +2614 -2437
- package/dist/index.systemjs.js +55 -55
- package/dist/index.umd.js +68 -68
- package/dist/src/feature-flags/FeatureFlagGuard.d.ts +35 -0
- package/dist/src/feature-flags/FeatureFlagsProvider.d.ts +79 -0
- package/dist/src/feature-flags/index.d.ts +39 -0
- package/dist/src/feature-flags/types.d.ts +114 -0
- package/dist/src/feature-flags/useFeatureFlag.d.ts +25 -0
- package/dist/src/feature-flags/useFeatureFlags.d.ts +9 -0
- package/dist/src/feature-flags/useVariant.d.ts +54 -0
- package/dist/src/hooks/applications/ApplicationMenu.d.ts +0 -2
- package/dist/src/hooks/index.d.ts +0 -1
- package/dist/src/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/src/hooks/applications/sortByDisplayOrder.d.ts +0 -10
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for the FeatureFlagGuard component
|
|
5
|
+
*/
|
|
6
|
+
export interface FeatureFlagGuardProps {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the feature flag to check
|
|
9
|
+
*/
|
|
10
|
+
flag: string;
|
|
11
|
+
/**
|
|
12
|
+
* Content to render when the flag is enabled (or disabled if inverted)
|
|
13
|
+
*/
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Optional content to render when the flag is disabled (or enabled if inverted)
|
|
17
|
+
* If not provided, nothing will be rendered when the flag is disabled
|
|
18
|
+
*/
|
|
19
|
+
fallback?: ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to invert the logic
|
|
22
|
+
* If true, children are shown when flag is disabled, fallback when enabled
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
invert?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Base URL for the gateway API
|
|
28
|
+
* @default ''
|
|
29
|
+
*/
|
|
30
|
+
gatewayUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Component for conditional rendering based on feature flags
|
|
34
|
+
*/
|
|
35
|
+
export declare const FeatureFlagGuard: FC<FeatureFlagGuardProps>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the feature flags context
|
|
5
|
+
*/
|
|
6
|
+
export interface FeatureFlagsContextValue {
|
|
7
|
+
/**
|
|
8
|
+
* Map of flag names to their boolean enabled state
|
|
9
|
+
*/
|
|
10
|
+
flags: Map<string, boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Map of flag names to their variant data
|
|
13
|
+
*/
|
|
14
|
+
variants: Map<string, {
|
|
15
|
+
variant: string | null;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the initial prefetch is in progress
|
|
20
|
+
*/
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Any error that occurred during flag fetching
|
|
24
|
+
*/
|
|
25
|
+
error: Error | null;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a cached flag is enabled
|
|
28
|
+
* @param flagName - Name of the flag to check
|
|
29
|
+
* @param defaultValue - Default value if flag is not in cache (default: false)
|
|
30
|
+
* @returns Whether the flag is enabled
|
|
31
|
+
*/
|
|
32
|
+
checkFlag: (flagName: string, defaultValue?: boolean) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get a cached variant value
|
|
35
|
+
* @param flagName - Name of the flag
|
|
36
|
+
* @returns Variant data or null if not in cache
|
|
37
|
+
*/
|
|
38
|
+
getVariant: (flagName: string) => {
|
|
39
|
+
variant: string | null;
|
|
40
|
+
payload: unknown;
|
|
41
|
+
} | null;
|
|
42
|
+
/**
|
|
43
|
+
* Manually refresh all prefetched flags
|
|
44
|
+
* @returns Promise that resolves when refresh is complete
|
|
45
|
+
*/
|
|
46
|
+
refresh: () => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Props for the FeatureFlagsProvider component
|
|
50
|
+
*/
|
|
51
|
+
export interface FeatureFlagsProviderProps {
|
|
52
|
+
/**
|
|
53
|
+
* Base URL for the gateway API
|
|
54
|
+
* @default ''
|
|
55
|
+
*/
|
|
56
|
+
gatewayUrl?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Array of flag names to prefetch on mount and refresh
|
|
59
|
+
* These flags will be eagerly loaded and cached
|
|
60
|
+
*/
|
|
61
|
+
prefetchFlags?: string[];
|
|
62
|
+
/**
|
|
63
|
+
* Interval in milliseconds for automatic refresh
|
|
64
|
+
* If not provided, automatic refresh is disabled
|
|
65
|
+
*/
|
|
66
|
+
refreshInterval?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Child components that will have access to the feature flags context
|
|
69
|
+
*/
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* React Context for feature flags
|
|
74
|
+
*/
|
|
75
|
+
export declare const FeatureFlagsContext: React.Context<FeatureFlagsContextValue>;
|
|
76
|
+
/**
|
|
77
|
+
* Provider component for feature flags
|
|
78
|
+
*/
|
|
79
|
+
export declare const FeatureFlagsProvider: React.FC<FeatureFlagsProviderProps>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature Flags React Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides React hooks and components for working with feature flags
|
|
5
|
+
* in the Blue Alba Platform. All utilities are compatible with the gateway's
|
|
6
|
+
* feature flags API (/_/feature-flags).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import {
|
|
11
|
+
* FeatureFlagsProvider,
|
|
12
|
+
* useFeatureFlag,
|
|
13
|
+
* useFeatureFlags,
|
|
14
|
+
* useVariant,
|
|
15
|
+
* FeatureFlagGuard
|
|
16
|
+
* } from '@bluealba/pae-ui-react-core';
|
|
17
|
+
*
|
|
18
|
+
* // Wrap your app with the provider
|
|
19
|
+
* <FeatureFlagsProvider
|
|
20
|
+
* gatewayUrl="/api"
|
|
21
|
+
* prefetchFlags={['new-ui', 'beta-feature']}
|
|
22
|
+
* refreshInterval={60000}
|
|
23
|
+
* >
|
|
24
|
+
* <App />
|
|
25
|
+
* </FeatureFlagsProvider>
|
|
26
|
+
*
|
|
27
|
+
* // Use in components
|
|
28
|
+
* function MyComponent() {
|
|
29
|
+
* const isEnabled = useFeatureFlag('new-ui');
|
|
30
|
+
* return isEnabled ? <NewUI /> : <OldUI />;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export type { FlagEvaluationResult, FeatureFlagVariant, FeatureFlagsResponse, SingleFlagResponse, VariantResponse, UnifiedEvaluationResponse, } from './types';
|
|
35
|
+
export { FeatureFlagsProvider, FeatureFlagsContext, type FeatureFlagsProviderProps, type FeatureFlagsContextValue, } from './FeatureFlagsProvider';
|
|
36
|
+
export { useFeatureFlag } from './useFeatureFlag';
|
|
37
|
+
export { useFeatureFlags } from './useFeatureFlags';
|
|
38
|
+
export { useVariant, type UseVariantResult } from './useVariant';
|
|
39
|
+
export { FeatureFlagGuard, type FeatureFlagGuardProps } from './FeatureFlagGuard';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for feature flags React utilities
|
|
3
|
+
* These types align with the gateway API responses
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Represents a variant in a feature flag evaluation result
|
|
7
|
+
*/
|
|
8
|
+
export interface FeatureFlagVariant {
|
|
9
|
+
/**
|
|
10
|
+
* Name of the variant
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the variant is enabled
|
|
15
|
+
*/
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Additional payload data for the variant
|
|
19
|
+
*/
|
|
20
|
+
payload?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of a feature flag evaluation
|
|
24
|
+
* Matches the FlagEvaluationResultDto from the gateway API
|
|
25
|
+
*/
|
|
26
|
+
export interface FlagEvaluationResult {
|
|
27
|
+
/**
|
|
28
|
+
* Name of the evaluated feature flag
|
|
29
|
+
*/
|
|
30
|
+
flagName: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the flag is enabled for the current context
|
|
33
|
+
*/
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Variant information (for multivariant flags)
|
|
37
|
+
*/
|
|
38
|
+
variant?: FeatureFlagVariant;
|
|
39
|
+
/**
|
|
40
|
+
* Timestamp when the flag was evaluated
|
|
41
|
+
*/
|
|
42
|
+
evaluatedAt: Date;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Response from bulk evaluate endpoint
|
|
46
|
+
*/
|
|
47
|
+
export interface FeatureFlagsResponse {
|
|
48
|
+
/**
|
|
49
|
+
* Array of flag evaluation results
|
|
50
|
+
*/
|
|
51
|
+
flags: FlagEvaluationResult[];
|
|
52
|
+
/**
|
|
53
|
+
* Timestamp when the evaluation was performed
|
|
54
|
+
*/
|
|
55
|
+
evaluatedAt: Date;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Response from single flag evaluation endpoint
|
|
59
|
+
*/
|
|
60
|
+
export interface SingleFlagResponse {
|
|
61
|
+
/**
|
|
62
|
+
* Name of the feature flag
|
|
63
|
+
*/
|
|
64
|
+
flagName: string;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the flag is enabled
|
|
67
|
+
*/
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Timestamp when the flag was evaluated
|
|
71
|
+
*/
|
|
72
|
+
evaluatedAt: Date;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Response from variant endpoint
|
|
76
|
+
*/
|
|
77
|
+
export interface VariantResponse {
|
|
78
|
+
/**
|
|
79
|
+
* Name of the feature flag
|
|
80
|
+
*/
|
|
81
|
+
flagName: string;
|
|
82
|
+
/**
|
|
83
|
+
* The selected variant name (undefined if no variant)
|
|
84
|
+
*/
|
|
85
|
+
variant: string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Timestamp when the variant was evaluated
|
|
88
|
+
*/
|
|
89
|
+
evaluatedAt: Date;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Unified evaluation response from the gateway API
|
|
93
|
+
* This is returned by the unified endpoint: GET /_/feature-flags/:flagName
|
|
94
|
+
*
|
|
95
|
+
* The value field contains:
|
|
96
|
+
* - For boolean flags: true or false
|
|
97
|
+
* - For variant flags: variant name (string), null, or undefined
|
|
98
|
+
*/
|
|
99
|
+
export interface UnifiedEvaluationResponse {
|
|
100
|
+
/**
|
|
101
|
+
* Name of the feature flag
|
|
102
|
+
*/
|
|
103
|
+
flagName: string;
|
|
104
|
+
/**
|
|
105
|
+
* The evaluated value of the flag
|
|
106
|
+
* - Boolean flags: true or false
|
|
107
|
+
* - Variant flags: variant name (string), null, or undefined
|
|
108
|
+
*/
|
|
109
|
+
value: boolean | string | null | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Timestamp when the flag was evaluated
|
|
112
|
+
*/
|
|
113
|
+
evaluatedAt: string;
|
|
114
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useFeatureFlag Hook
|
|
3
|
+
*
|
|
4
|
+
* A React hook for evaluating a single boolean feature flag.
|
|
5
|
+
* This hook first checks if the flag is in the prefetched cache (from FeatureFlagsProvider).
|
|
6
|
+
* If not found in cache, it fetches the flag individually from the API.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function MyComponent() {
|
|
11
|
+
* const isNewUIEnabled = useFeatureFlag('new-ui', false);
|
|
12
|
+
*
|
|
13
|
+
* return isNewUIEnabled ? <NewUI /> : <OldUI />;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Hook for evaluating a single boolean feature flag
|
|
19
|
+
*
|
|
20
|
+
* @param flagName - Name of the feature flag to evaluate
|
|
21
|
+
* @param defaultValue - Default value to use if flag cannot be evaluated (default: false)
|
|
22
|
+
* @param gatewayUrl - Base URL for the gateway API (default: '')
|
|
23
|
+
* @returns Boolean indicating whether the flag is enabled
|
|
24
|
+
*/
|
|
25
|
+
export declare function useFeatureFlag(flagName: string, defaultValue?: boolean, gatewayUrl?: string): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FeatureFlagsContextValue } from './FeatureFlagsProvider';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook for accessing the feature flags context
|
|
5
|
+
*
|
|
6
|
+
* @throws Error if used outside of FeatureFlagsProvider
|
|
7
|
+
* @returns The full feature flags context
|
|
8
|
+
*/
|
|
9
|
+
export declare function useFeatureFlags(): FeatureFlagsContextValue;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useVariant Hook
|
|
3
|
+
*
|
|
4
|
+
* A React hook for getting the variant value of a multivariant feature flag.
|
|
5
|
+
* This hook first checks if the variant is in the prefetched cache (from FeatureFlagsProvider).
|
|
6
|
+
* If not found in cache, it fetches the variant individually from the unified API.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: The unified individual API endpoint does NOT return the payload.
|
|
9
|
+
* To get payload data, you should either:
|
|
10
|
+
* 1. Use FeatureFlagsProvider with prefetchFlags to cache the variant with payload
|
|
11
|
+
* 2. Use the bulk evaluate endpoint directly if you need payload for single flags
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* function MyComponent() {
|
|
16
|
+
* const { variant, payload, isLoading } = useVariant('checkout-flow');
|
|
17
|
+
*
|
|
18
|
+
* if (isLoading) return <Spinner />;
|
|
19
|
+
*
|
|
20
|
+
* if (variant === 'new-checkout') {
|
|
21
|
+
* return <NewCheckout config={payload} />;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* return <OldCheckout />;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Return type for the useVariant hook
|
|
30
|
+
*/
|
|
31
|
+
export interface UseVariantResult {
|
|
32
|
+
/**
|
|
33
|
+
* The selected variant name, or null if no variant is selected
|
|
34
|
+
*/
|
|
35
|
+
variant: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* The payload data associated with the variant
|
|
38
|
+
* Note: Only available if the variant was fetched via FeatureFlagsProvider (prefetch)
|
|
39
|
+
* The individual variant endpoint does not return payload
|
|
40
|
+
*/
|
|
41
|
+
payload: unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the variant is currently being loaded
|
|
44
|
+
*/
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Hook for getting the variant value of a multivariant feature flag
|
|
49
|
+
*
|
|
50
|
+
* @param flagName - Name of the feature flag
|
|
51
|
+
* @param gatewayUrl - Base URL for the gateway API (default: '')
|
|
52
|
+
* @returns Object containing variant, payload, and loading state
|
|
53
|
+
*/
|
|
54
|
+
export declare function useVariant(flagName: string, gatewayUrl?: string): UseVariantResult;
|
|
@@ -5,7 +5,6 @@ export type AplicationMenuSubItem = {
|
|
|
5
5
|
path?: string;
|
|
6
6
|
Icon?: React.ReactNode;
|
|
7
7
|
operations?: string[];
|
|
8
|
-
displayOrder?: number;
|
|
9
8
|
};
|
|
10
9
|
export type ApplicationMenuItem = {
|
|
11
10
|
label: string;
|
|
@@ -17,6 +16,5 @@ export type ApplicationMenuItem = {
|
|
|
17
16
|
canCollapse?: boolean;
|
|
18
17
|
externalUrl?: string;
|
|
19
18
|
target?: '_self' | '_blank';
|
|
20
|
-
displayOrder?: number;
|
|
21
19
|
};
|
|
22
20
|
export type ApplicationMenu = ApplicationMenuItem[];
|
|
@@ -21,7 +21,6 @@ export { useCurrentApplication } from './applications/useCurrentApplication';
|
|
|
21
21
|
export { useCurrentJSModule } from './applications/useCurrentJSModule';
|
|
22
22
|
export { type ApplicationMenu, type ApplicationMenuItem } from './applications/ApplicationMenu';
|
|
23
23
|
export { type PlatformApplication } from './applications/PlatformApplication';
|
|
24
|
-
export { sortByDisplayOrder } from './applications/sortByDisplayOrder';
|
|
25
24
|
export { useAuth } from './useAuth';
|
|
26
25
|
export { useOperations } from './useOperations';
|
|
27
26
|
export { useServiceInvoker, type ServiceInvoker } from './useServiceInvoker';
|
package/dist/src/index.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export * from './components/common';
|
|
|
9
9
|
export { default as initializeMicroFrontend } from './utils/initializeMicroFrontend';
|
|
10
10
|
export * from './MicrofrontendProps';
|
|
11
11
|
export { setupTestEnvironment } from './test-utils/setupTestEnvironment';
|
|
12
|
+
export * from './feature-flags';
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sorts items by displayOrder in descending order (higher numbers first).
|
|
3
|
-
* Items without displayOrder maintain their original order (stable sort).
|
|
4
|
-
*
|
|
5
|
-
* @param items - Array of items to sort
|
|
6
|
-
* @returns New sorted array
|
|
7
|
-
*/
|
|
8
|
-
export declare function sortByDisplayOrder<T extends {
|
|
9
|
-
displayOrder?: number;
|
|
10
|
-
}>(items: T[]): T[];
|