@plyaz/types 1.1.2 → 1.1.4
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/auth/schemas.d.ts +1 -1
- package/dist/features/cache/index.d.ts +1 -0
- package/dist/features/cache/types.d.ts +142 -0
- package/dist/features/feature-flag/index.d.ts +1 -0
- package/dist/features/feature-flag/types.d.ts +302 -0
- package/dist/features/index.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/translations/types.d.ts +96 -2
- package/package.json +1 -1
package/dist/auth/schemas.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Types and Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the caching layer.
|
|
5
|
+
* This will be moved to @plyaz/core when the package structure is finalized.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Cache type definitions
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Cache entry structure that wraps cached data with metadata.
|
|
12
|
+
*/
|
|
13
|
+
export interface CacheEntry<T = unknown> {
|
|
14
|
+
/** The cached data */
|
|
15
|
+
data: T;
|
|
16
|
+
/** When the entry expires (timestamp in milliseconds) */
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
/** When the entry was created (timestamp in milliseconds) */
|
|
19
|
+
createdAt: number;
|
|
20
|
+
/** Optional metadata for the cache entry */
|
|
21
|
+
meta?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Cache statistics for monitoring and debugging.
|
|
25
|
+
*/
|
|
26
|
+
export interface CacheStats {
|
|
27
|
+
/** Total number of cache hits */
|
|
28
|
+
hits: number;
|
|
29
|
+
/** Total number of cache misses */
|
|
30
|
+
misses: number;
|
|
31
|
+
/** Total number of set operations */
|
|
32
|
+
sets: number;
|
|
33
|
+
/** Total number of delete operations */
|
|
34
|
+
deletes: number;
|
|
35
|
+
/** Number of entries currently in cache */
|
|
36
|
+
size: number;
|
|
37
|
+
/** Cache hit ratio (hits / (hits + misses)) */
|
|
38
|
+
hitRatio?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for cache strategies.
|
|
42
|
+
*/
|
|
43
|
+
export interface CacheConfig {
|
|
44
|
+
/** Whether caching is enabled */
|
|
45
|
+
isEnabled: boolean;
|
|
46
|
+
/** Default TTL in seconds */
|
|
47
|
+
ttl: number;
|
|
48
|
+
/** Cache strategy to use */
|
|
49
|
+
strategy: 'memory' | 'redis';
|
|
50
|
+
/** Redis-specific configuration */
|
|
51
|
+
redisConfig?: RedisCacheConfig;
|
|
52
|
+
/** Memory cache specific configuration */
|
|
53
|
+
memoryConfig?: {
|
|
54
|
+
/** Maximum number of entries to store */
|
|
55
|
+
maxSize?: number;
|
|
56
|
+
/** Maximum number of entries to store (alias for maxSize) */
|
|
57
|
+
maxEntries?: number;
|
|
58
|
+
/** Check for expired entries every N milliseconds */
|
|
59
|
+
cleanupInterval?: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for memory cache strategy.
|
|
64
|
+
*/
|
|
65
|
+
export interface MemoryCacheConfig {
|
|
66
|
+
/** Maximum number of entries to store (default: 1000) */
|
|
67
|
+
maxSize?: number;
|
|
68
|
+
/** Maximum number of entries to store (alias for maxSize) */
|
|
69
|
+
maxEntries?: number;
|
|
70
|
+
/** Check for expired entries every N milliseconds (default: 60000) */
|
|
71
|
+
cleanupInterval?: number;
|
|
72
|
+
/** Callback when entry is evicted */
|
|
73
|
+
onEvict?: (key: string, entry: CacheEntry) => void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Configuration for Redis cache strategy.
|
|
77
|
+
*/
|
|
78
|
+
export interface RedisCacheConfig {
|
|
79
|
+
/** Redis connection URL */
|
|
80
|
+
url: string;
|
|
81
|
+
/** Redis password for authentication */
|
|
82
|
+
password?: string;
|
|
83
|
+
/** Redis database number */
|
|
84
|
+
db?: number;
|
|
85
|
+
/** Key prefix for Redis keys */
|
|
86
|
+
keyPrefix?: string;
|
|
87
|
+
/** Connection timeout in milliseconds */
|
|
88
|
+
connectTimeout?: number;
|
|
89
|
+
/** Command timeout in milliseconds */
|
|
90
|
+
commandTimeout?: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Cache manager statistics interface.
|
|
94
|
+
*/
|
|
95
|
+
export interface CacheManagerStats extends CacheStats {
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Interface that all cache strategies must implement.
|
|
99
|
+
*/
|
|
100
|
+
export interface CacheStrategy {
|
|
101
|
+
/**
|
|
102
|
+
* Stores a cache entry.
|
|
103
|
+
*
|
|
104
|
+
* @param key - Cache key
|
|
105
|
+
* @param entry - Cache entry to store
|
|
106
|
+
* @returns Promise that resolves when entry is stored
|
|
107
|
+
*/
|
|
108
|
+
set<T>(key: string, entry: CacheEntry<T>): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a cache entry.
|
|
111
|
+
*
|
|
112
|
+
* @param key - Cache key
|
|
113
|
+
* @returns Promise that resolves to cache entry or null if not found
|
|
114
|
+
*/
|
|
115
|
+
get<T>(key: string): Promise<CacheEntry<T> | null>;
|
|
116
|
+
/**
|
|
117
|
+
* Removes a cache entry.
|
|
118
|
+
*
|
|
119
|
+
* @param key - Cache key to remove
|
|
120
|
+
* @returns Promise that resolves when entry is removed
|
|
121
|
+
*/
|
|
122
|
+
delete(key: string): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Clears all cache entries.
|
|
125
|
+
*
|
|
126
|
+
* @returns Promise that resolves when cache is cleared
|
|
127
|
+
*/
|
|
128
|
+
clear(): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Gets cache statistics.
|
|
131
|
+
*
|
|
132
|
+
* @returns Promise that resolves to cache statistics
|
|
133
|
+
*/
|
|
134
|
+
getStats(): Promise<CacheStats>;
|
|
135
|
+
/**
|
|
136
|
+
* Disposes of the cache strategy and cleans up resources.
|
|
137
|
+
* Optional method for cleanup.
|
|
138
|
+
*
|
|
139
|
+
* @returns Promise that resolves when cleanup is complete
|
|
140
|
+
*/
|
|
141
|
+
dispose?(): Promise<void>;
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature Flags Domain Types
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions for the feature flags domain.
|
|
5
|
+
* These types will be moved to @plyaz/types when the package structure is finalized.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Feature flags domain type definitions
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
import type * as React from 'react';
|
|
11
|
+
/**
|
|
12
|
+
* Possible values that a feature flag can hold.
|
|
13
|
+
* Supports primitive types and JSON objects for complex configurations.
|
|
14
|
+
*/
|
|
15
|
+
export type FeatureFlagValue = boolean | string | number | Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Core feature flag definition interface.
|
|
18
|
+
* Represents a complete feature flag with all its metadata and configuration.
|
|
19
|
+
*/
|
|
20
|
+
export interface FeatureFlag<FeatureFlagKey> {
|
|
21
|
+
/** The unique identifier for this flag */
|
|
22
|
+
key: FeatureFlagKey;
|
|
23
|
+
/** Human-readable name for the flag */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Detailed description of what this flag controls */
|
|
26
|
+
description: string;
|
|
27
|
+
/** Whether this flag is currently active */
|
|
28
|
+
isEnabled: boolean;
|
|
29
|
+
/** The value returned when this flag is evaluated */
|
|
30
|
+
value: FeatureFlagValue;
|
|
31
|
+
/** The data type of the flag value */
|
|
32
|
+
type: 'boolean' | 'string' | 'number' | 'json';
|
|
33
|
+
/** Which environment(s) this flag applies to */
|
|
34
|
+
environment: 'development' | 'staging' | 'production' | 'all';
|
|
35
|
+
/** Percentage of users who should receive this flag (0-100) */
|
|
36
|
+
rolloutPercentage?: number;
|
|
37
|
+
/** Timestamp when this flag was created */
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
/** Timestamp when this flag was last updated */
|
|
40
|
+
updatedAt: Date;
|
|
41
|
+
/** Email or ID of the user who created this flag */
|
|
42
|
+
createdBy: string;
|
|
43
|
+
/** Email or ID of the user who last updated this flag */
|
|
44
|
+
updatedBy: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Feature flag rule for advanced targeting and conditional logic.
|
|
48
|
+
*/
|
|
49
|
+
export interface FeatureFlagRule<FeatureFlagKey> {
|
|
50
|
+
/** Unique identifier for this rule */
|
|
51
|
+
id: string;
|
|
52
|
+
/** The feature flag this rule applies to */
|
|
53
|
+
flagKey: FeatureFlagKey;
|
|
54
|
+
/** Human-readable name for this rule */
|
|
55
|
+
name: string;
|
|
56
|
+
/** Array of conditions that must all be met for this rule to apply */
|
|
57
|
+
conditions: FeatureFlagCondition[];
|
|
58
|
+
/** The value to return if this rule matches */
|
|
59
|
+
value: FeatureFlagValue;
|
|
60
|
+
/** Percentage of matching users who should receive this value (0-100) */
|
|
61
|
+
rolloutPercentage?: number;
|
|
62
|
+
/** Priority for rule evaluation (higher numbers = higher priority) */
|
|
63
|
+
priority: number;
|
|
64
|
+
/** Whether this rule is currently active */
|
|
65
|
+
isEnabled: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Individual condition for feature flag rule evaluation.
|
|
69
|
+
*/
|
|
70
|
+
export interface FeatureFlagCondition {
|
|
71
|
+
/** The context field to evaluate */
|
|
72
|
+
field: 'userId' | 'userEmail' | 'userRole' | 'country' | 'platform' | 'version' | 'environment' | 'custom';
|
|
73
|
+
/** The comparison operator to use */
|
|
74
|
+
operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in' | 'greater_than' | 'less_than';
|
|
75
|
+
/** The value(s) to compare against */
|
|
76
|
+
value: string | number | string[] | number[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Context information used for feature flag evaluation.
|
|
80
|
+
*/
|
|
81
|
+
export interface FeatureFlagContext {
|
|
82
|
+
/** Unique identifier for the user */
|
|
83
|
+
userId?: string;
|
|
84
|
+
/** User's email address */
|
|
85
|
+
userEmail?: string;
|
|
86
|
+
/** User's role or permission level */
|
|
87
|
+
userRole?: string;
|
|
88
|
+
/** User's country code (ISO 3166-1 alpha-2) */
|
|
89
|
+
country?: string;
|
|
90
|
+
/** Platform the user is accessing from */
|
|
91
|
+
platform?: 'web' | 'mobile' | 'desktop';
|
|
92
|
+
/** Application version */
|
|
93
|
+
version?: string;
|
|
94
|
+
/** Custom context data for advanced targeting */
|
|
95
|
+
custom?: Record<string, unknown>;
|
|
96
|
+
/** Current environment */
|
|
97
|
+
environment: 'development' | 'staging' | 'production';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Result of a feature flag evaluation.
|
|
101
|
+
*/
|
|
102
|
+
export interface FeatureFlagEvaluation<FeatureFlagKey> {
|
|
103
|
+
/** The feature flag key that was evaluated */
|
|
104
|
+
flagKey: FeatureFlagKey;
|
|
105
|
+
/** The resolved value for this flag */
|
|
106
|
+
value: FeatureFlagValue;
|
|
107
|
+
/** Whether the flag is considered enabled (truthy value) */
|
|
108
|
+
isEnabled: boolean;
|
|
109
|
+
/** Explanation of how this value was determined */
|
|
110
|
+
reason: 'default' | 'rule_match' | 'rollout' | 'override' | 'disabled';
|
|
111
|
+
/** Source of the evaluation result */
|
|
112
|
+
source?: 'default' | 'override' | 'rule' | 'rollout';
|
|
113
|
+
/** ID of the rule that matched (if reason is 'rule_match') */
|
|
114
|
+
ruleId?: string;
|
|
115
|
+
/** Timestamp when this evaluation occurred */
|
|
116
|
+
evaluatedAt: Date;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Configuration options for the feature flag system.
|
|
120
|
+
*/
|
|
121
|
+
export interface FeatureFlagConfig<FeatureFlagKey> {
|
|
122
|
+
/** The storage provider to use for flag data */
|
|
123
|
+
provider: 'database' | 'redis' | 'memory' | 'api' | 'file';
|
|
124
|
+
/** Whether to enable caching of flag evaluations */
|
|
125
|
+
isCacheEnabled: boolean;
|
|
126
|
+
/** Cache time-to-live in seconds */
|
|
127
|
+
cacheTtl: number;
|
|
128
|
+
/** How often to refresh flag data in seconds (0 = no auto-refresh) */
|
|
129
|
+
refreshInterval: number;
|
|
130
|
+
/** Whether to fall back to default values on errors */
|
|
131
|
+
shouldFallbackToDefaults: boolean;
|
|
132
|
+
/** Whether to enable debug logging */
|
|
133
|
+
isLoggingEnabled: boolean;
|
|
134
|
+
/** API endpoint URL (required if provider is 'api') */
|
|
135
|
+
apiEndpoint?: string;
|
|
136
|
+
/** API authentication key (required if provider is 'api') */
|
|
137
|
+
apiKey?: string;
|
|
138
|
+
/** Database configuration (required if provider is 'database') */
|
|
139
|
+
databaseConfig?: {
|
|
140
|
+
connectionString: string;
|
|
141
|
+
tableName: string;
|
|
142
|
+
};
|
|
143
|
+
/** Redis configuration (required if provider is 'redis') */
|
|
144
|
+
redisConfig?: {
|
|
145
|
+
url: string;
|
|
146
|
+
keyPrefix: string;
|
|
147
|
+
};
|
|
148
|
+
/** File configuration (required if provider is 'file') */
|
|
149
|
+
fileConfig?: {
|
|
150
|
+
filePath: string;
|
|
151
|
+
format: 'json' | 'yaml';
|
|
152
|
+
shouldWatchForChanges: boolean;
|
|
153
|
+
};
|
|
154
|
+
/** Memory provider rules (optional for memory provider) */
|
|
155
|
+
memoryRules?: FeatureFlagRule<FeatureFlagKey>[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* React Hook Options for Feature Flags
|
|
159
|
+
*/
|
|
160
|
+
export interface UseFeatureFlagOptions {
|
|
161
|
+
/** Evaluation context for targeting */
|
|
162
|
+
context?: FeatureFlagContext;
|
|
163
|
+
/** Whether to automatically refresh on provider updates */
|
|
164
|
+
isAutoRefresh?: boolean;
|
|
165
|
+
/** Default value to use while loading or on error */
|
|
166
|
+
defaultValue?: FeatureFlagValue;
|
|
167
|
+
/** Whether to suspend on initial load (for Suspense) */
|
|
168
|
+
isSuspense?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Internal state for feature flag evaluation in React hooks.
|
|
172
|
+
*/
|
|
173
|
+
export interface FeatureFlagState<FeatureFlagKey, T extends FeatureFlagValue = FeatureFlagValue> {
|
|
174
|
+
value: T;
|
|
175
|
+
isLoading: boolean;
|
|
176
|
+
error: Error | null;
|
|
177
|
+
evaluation: FeatureFlagEvaluation<FeatureFlagKey> | null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Context value interface for React feature flag provider.
|
|
181
|
+
*/
|
|
182
|
+
export interface FeatureFlagContextValue<FeatureFlagKey> {
|
|
183
|
+
/** The feature flag provider instance */
|
|
184
|
+
provider: FeatureFlagProvider<FeatureFlagKey>;
|
|
185
|
+
/** Whether the provider is initialized */
|
|
186
|
+
isInitialized: boolean;
|
|
187
|
+
/** Whether the provider is currently loading */
|
|
188
|
+
isLoading: boolean;
|
|
189
|
+
/** Any error that occurred during initialization */
|
|
190
|
+
error: Error | null;
|
|
191
|
+
/** When the provider was last updated */
|
|
192
|
+
lastUpdated: Date | null;
|
|
193
|
+
/** Manual refresh function */
|
|
194
|
+
refresh: () => Promise<void>;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Props for the React FeatureFlagProvider component.
|
|
198
|
+
*/
|
|
199
|
+
export interface FeatureFlagProviderProps<FeatureFlagKey> {
|
|
200
|
+
/** Provider configuration */
|
|
201
|
+
config: FeatureFlagConfig<FeatureFlagKey>;
|
|
202
|
+
/** Default context for flag evaluation */
|
|
203
|
+
defaultContext?: FeatureFlagContext;
|
|
204
|
+
/** Children components */
|
|
205
|
+
children: React.ReactNode;
|
|
206
|
+
/** Callback when provider is ready */
|
|
207
|
+
onReady?: (provider: FeatureFlagProvider<FeatureFlagKey>) => void;
|
|
208
|
+
/** Callback when an error occurs */
|
|
209
|
+
onError?: (error: Error) => void;
|
|
210
|
+
/** Whether to show loading state while initializing */
|
|
211
|
+
isShowLoading?: boolean;
|
|
212
|
+
/** Custom loading component */
|
|
213
|
+
loadingComponent?: React.ComponentType;
|
|
214
|
+
/** Custom error component */
|
|
215
|
+
errorComponent?: React.ComponentType<{
|
|
216
|
+
error: Error;
|
|
217
|
+
retry: () => void;
|
|
218
|
+
}>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Backend Request DTO for flag creation.
|
|
222
|
+
*/
|
|
223
|
+
export interface CreateFlagRequest<FeatureFlagKey> {
|
|
224
|
+
key: FeatureFlagKey;
|
|
225
|
+
name: string;
|
|
226
|
+
description?: string;
|
|
227
|
+
value: FeatureFlagValue;
|
|
228
|
+
isEnabled?: boolean;
|
|
229
|
+
environment?: 'all' | 'development' | 'staging' | 'production';
|
|
230
|
+
rolloutPercentage?: number;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Backend Provider health status information.
|
|
234
|
+
*/
|
|
235
|
+
export interface ProviderHealthStatus {
|
|
236
|
+
isInitialized: boolean;
|
|
237
|
+
provider: string;
|
|
238
|
+
isCacheEnabled: boolean;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Main interface for feature flag providers.
|
|
242
|
+
*/
|
|
243
|
+
export interface FeatureFlagProvider<FeatureFlagKey> {
|
|
244
|
+
/** Initializes the provider by loading initial data */
|
|
245
|
+
initialize(): Promise<void>;
|
|
246
|
+
/** Evaluates a feature flag and returns full evaluation details */
|
|
247
|
+
getFlag(key: FeatureFlagKey, context?: FeatureFlagContext): Promise<FeatureFlagEvaluation<FeatureFlagKey>>;
|
|
248
|
+
/** Evaluates all feature flags for the given context */
|
|
249
|
+
getAllFlags(context?: FeatureFlagContext): Promise<Record<string, FeatureFlagEvaluation<FeatureFlagKey>>>;
|
|
250
|
+
/** Checks if a feature flag is enabled */
|
|
251
|
+
isEnabled(key: FeatureFlagKey, context?: FeatureFlagContext): Promise<boolean>;
|
|
252
|
+
/** Gets the value of a feature flag with optional type casting */
|
|
253
|
+
getValue<T = FeatureFlagValue>(key: FeatureFlagKey, context?: FeatureFlagContext): Promise<T>;
|
|
254
|
+
/** Refreshes the flag data from the underlying storage */
|
|
255
|
+
refresh(): Promise<void>;
|
|
256
|
+
/** Subscribes to flag changes and updates */
|
|
257
|
+
subscribe(callback: () => void): () => void;
|
|
258
|
+
/** Sets an override for a specific flag key */
|
|
259
|
+
setOverride(key: FeatureFlagKey, value: FeatureFlagValue): void;
|
|
260
|
+
/** Removes an override for a specific flag key */
|
|
261
|
+
removeOverride(key: FeatureFlagKey): void;
|
|
262
|
+
/** Clears all overrides */
|
|
263
|
+
clearOverrides(): void;
|
|
264
|
+
/** Disposes of the provider, cleaning up resources */
|
|
265
|
+
dispose(): void;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Partial mapping for flag overrides.
|
|
269
|
+
*/
|
|
270
|
+
export type FeatureFlagOverrides<FeatureFlagKey extends string = string> = Partial<{
|
|
271
|
+
[K in FeatureFlagKey]: FeatureFlagValue;
|
|
272
|
+
}>;
|
|
273
|
+
/**
|
|
274
|
+
* Hook-like interface for reactive feature flag usage.
|
|
275
|
+
*/
|
|
276
|
+
export type FeatureFlagHook<T = boolean> = {
|
|
277
|
+
/** The current value of the flag */
|
|
278
|
+
value: T;
|
|
279
|
+
/** Whether the flag is currently being loaded */
|
|
280
|
+
isLoading: boolean;
|
|
281
|
+
/** Any error that occurred during flag evaluation */
|
|
282
|
+
error: Error | null;
|
|
283
|
+
/** Function to manually refresh the flag value */
|
|
284
|
+
refresh: () => Promise<void>;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Helper functions for managing feature flags.
|
|
288
|
+
*/
|
|
289
|
+
export interface FeatureFlagHelpers<FeatureFlagKey extends string = string> {
|
|
290
|
+
setOverride: (key: FeatureFlagKey, value: FeatureFlagValue) => void;
|
|
291
|
+
removeOverride: (key: FeatureFlagKey) => void;
|
|
292
|
+
clearOverrides: () => void;
|
|
293
|
+
refresh: () => Promise<void>;
|
|
294
|
+
getMultipleFlags: (keys: FeatureFlagKey[], context?: FeatureFlagContext) => Promise<Record<FeatureFlagKey, FeatureFlagValue>>;
|
|
295
|
+
isAnyEnabled: (keys: FeatureFlagKey[], context?: FeatureFlagContext) => Promise<boolean>;
|
|
296
|
+
isAllEnabled: (keys: FeatureFlagKey[], context?: FeatureFlagContext) => Promise<boolean>;
|
|
297
|
+
whenEnabled: <T>(key: FeatureFlagKey, callback: () => T | Promise<T>, fallback?: () => T | Promise<T>, context?: FeatureFlagContext) => Promise<T | undefined>;
|
|
298
|
+
}
|
|
299
|
+
export interface FetchFeatureFlagDataResponse<FeatureFlagKey> {
|
|
300
|
+
flags: FeatureFlag<FeatureFlagKey>[];
|
|
301
|
+
rules: FeatureFlagRule<FeatureFlagKey>[];
|
|
302
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Paths, Get } from 'type-fest';
|
|
2
1
|
/**
|
|
3
2
|
* Translation leaf type.
|
|
4
3
|
* @description This type represents the structure of a translation leaf.
|
|
@@ -37,12 +36,56 @@ TranslationResourcesNested>>;
|
|
|
37
36
|
* @example 'common', 'errors', etc.
|
|
38
37
|
*/
|
|
39
38
|
export type Namespace<Resources extends TranslationResources> = keyof Resources['en'];
|
|
39
|
+
/**
|
|
40
|
+
* Helper type to remove the first element from a tuple type.
|
|
41
|
+
* Used internally by LeafPaths to track recursion depth.
|
|
42
|
+
*/
|
|
43
|
+
type PrevTuple<T extends readonly unknown[]> = T extends [unknown, ...infer R] ? R : [];
|
|
40
44
|
/**
|
|
41
45
|
* Recursively extracts all nested keys from an object, creating dot-notation paths.
|
|
46
|
+
* @description This utility type traverses nested objects and creates dot-separated key paths.
|
|
47
|
+
* It uses a depth counter to prevent infinite recursion (max 25 levels, which should be sufficient
|
|
48
|
+
* for most translation structures while avoiding TypeScript compiler limits).
|
|
49
|
+
* @example
|
|
50
|
+
* type Paths = LeafPaths<{ a: { b: string, c: { d: string } } }>;
|
|
51
|
+
* // Result: 'a.b' | 'a.c.d'
|
|
52
|
+
* @template T - The object type to extract paths from
|
|
53
|
+
* @template Prev - The accumulated path string (used internally)
|
|
54
|
+
* @template Depth - Tuple type used to track recursion depth and prevent infinite loops
|
|
42
55
|
*/
|
|
43
|
-
export type LeafPaths<T
|
|
56
|
+
export type LeafPaths<T, Prev extends string = '', Depth extends readonly unknown[] = [
|
|
57
|
+
1,
|
|
58
|
+
1,
|
|
59
|
+
1,
|
|
60
|
+
1,
|
|
61
|
+
1,
|
|
62
|
+
1,
|
|
63
|
+
1,
|
|
64
|
+
1,
|
|
65
|
+
1,
|
|
66
|
+
1,
|
|
67
|
+
1,
|
|
68
|
+
1,
|
|
69
|
+
1,
|
|
70
|
+
1,
|
|
71
|
+
1,
|
|
72
|
+
1,
|
|
73
|
+
1,
|
|
74
|
+
1,
|
|
75
|
+
1,
|
|
76
|
+
1,
|
|
77
|
+
1,
|
|
78
|
+
1,
|
|
79
|
+
1,
|
|
80
|
+
1,
|
|
81
|
+
1
|
|
82
|
+
]> = Depth['length'] extends 0 ? never : T extends string ? Prev : T extends object ? {
|
|
83
|
+
[K in keyof T]: LeafPaths<T[K], Prev extends '' ? Extract<K, string> : `${Prev}.${Extract<K, string>}`, PrevTuple<Depth>>;
|
|
84
|
+
}[keyof T] : never;
|
|
44
85
|
/**
|
|
45
86
|
* Type-safe union of all translation keys in the form 'namespace.key' or 'namespace.nested.key'.
|
|
87
|
+
* @description This type generates a union of all possible translation keys by combining
|
|
88
|
+
* namespace names with their nested key paths. It ensures type safety when accessing translations.
|
|
46
89
|
* @example 'common.hello', 'common.greeting', 'common.followers.zero', etc.
|
|
47
90
|
* @example use: TranslationKeys<TranslationResources, 'en'>
|
|
48
91
|
*/
|
|
@@ -218,6 +261,11 @@ export interface Translator {
|
|
|
218
261
|
*/
|
|
219
262
|
readonly addNamespace: (namespace: string, translations: Record<string, string>) => void;
|
|
220
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Command-line interface options for extracting translation keys from source code.
|
|
266
|
+
* @description These types define the configuration options for the CLI tool that
|
|
267
|
+
* automatically extracts translation keys from source files and generates translation files.
|
|
268
|
+
*/
|
|
221
269
|
export interface ExtractOptions {
|
|
222
270
|
/**
|
|
223
271
|
* File pattern to search for translation keys
|
|
@@ -240,6 +288,16 @@ export interface ExtractOptions {
|
|
|
240
288
|
*/
|
|
241
289
|
readonly shouldDryRun: boolean;
|
|
242
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Pluralization test cases for validating translation pluralization rules.
|
|
293
|
+
* @description These types define the structure for testing pluralization functionality
|
|
294
|
+
* across different languages, ensuring correct plural forms are used based on numeric values.
|
|
295
|
+
*/
|
|
296
|
+
/**
|
|
297
|
+
* Represents a single test case for pluralization validation.
|
|
298
|
+
* @description Defines a numeric value and its expected translation string
|
|
299
|
+
* to test pluralization rules in different languages.
|
|
300
|
+
*/
|
|
243
301
|
export interface PluralizationValueCase {
|
|
244
302
|
/**
|
|
245
303
|
* The numeric value to test pluralization against
|
|
@@ -250,6 +308,11 @@ export interface PluralizationValueCase {
|
|
|
250
308
|
*/
|
|
251
309
|
readonly expected: string;
|
|
252
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Represents a complete set of pluralization test cases for a specific language.
|
|
313
|
+
* @description Groups multiple pluralization value cases together for a single language,
|
|
314
|
+
* allowing comprehensive testing of pluralization rules across different numeric values.
|
|
315
|
+
*/
|
|
253
316
|
export interface PluralizationCase {
|
|
254
317
|
/**
|
|
255
318
|
* The language code for this pluralization case
|
|
@@ -260,6 +323,16 @@ export interface PluralizationCase {
|
|
|
260
323
|
*/
|
|
261
324
|
readonly values: readonly PluralizationValueCase[];
|
|
262
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Date formatting test cases for validating locale-specific date formatting.
|
|
328
|
+
* @description These types define the structure for testing date formatting functionality
|
|
329
|
+
* across different languages and locales.
|
|
330
|
+
*/
|
|
331
|
+
/**
|
|
332
|
+
* Represents a test case for date formatting validation.
|
|
333
|
+
* @description Defines a language and its expected formatted date string
|
|
334
|
+
* to test date formatting rules in different locales.
|
|
335
|
+
*/
|
|
263
336
|
export interface DateCase {
|
|
264
337
|
/**
|
|
265
338
|
* The language code for this date formatting case
|
|
@@ -270,6 +343,16 @@ export interface DateCase {
|
|
|
270
343
|
*/
|
|
271
344
|
readonly expected: string;
|
|
272
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Number formatting test cases for validating locale-specific number formatting.
|
|
348
|
+
* @description These types define the structure for testing number formatting functionality
|
|
349
|
+
* across different languages and locales.
|
|
350
|
+
*/
|
|
351
|
+
/**
|
|
352
|
+
* Represents a test case for number formatting validation.
|
|
353
|
+
* @description Defines a language and its expected formatted number string
|
|
354
|
+
* to test number formatting rules in different locales.
|
|
355
|
+
*/
|
|
273
356
|
export interface NumberCase {
|
|
274
357
|
/**
|
|
275
358
|
* The language code for this number formatting case
|
|
@@ -280,6 +363,16 @@ export interface NumberCase {
|
|
|
280
363
|
*/
|
|
281
364
|
readonly expected: string;
|
|
282
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Currency formatting test cases for validating locale-specific currency formatting.
|
|
368
|
+
* @description These types define the structure for testing currency formatting functionality
|
|
369
|
+
* across different languages and locales, including currency symbols and formatting options.
|
|
370
|
+
*/
|
|
371
|
+
/**
|
|
372
|
+
* Represents a test case for currency formatting validation.
|
|
373
|
+
* @description Defines a language, expected formatted currency string, and formatting options
|
|
374
|
+
* to test currency formatting rules in different locales.
|
|
375
|
+
*/
|
|
283
376
|
export interface CurrencyCase {
|
|
284
377
|
/**
|
|
285
378
|
* The language code for this currency formatting case
|
|
@@ -294,3 +387,4 @@ export interface CurrencyCase {
|
|
|
294
387
|
*/
|
|
295
388
|
readonly options: Intl.NumberFormatOptions;
|
|
296
389
|
}
|
|
390
|
+
export {};
|
package/package.json
CHANGED