@plyaz/core 1.0.0

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 (82) hide show
  1. package/README.md +439 -0
  2. package/dist/backend/featureFlags/feature-flag.controller.d.ts +135 -0
  3. package/dist/backend/featureFlags/feature-flag.controller.d.ts.map +1 -0
  4. package/dist/backend/featureFlags/feature-flag.module.d.ts +114 -0
  5. package/dist/backend/featureFlags/feature-flag.module.d.ts.map +1 -0
  6. package/dist/backend/featureFlags/feature-flag.repository.d.ts +85 -0
  7. package/dist/backend/featureFlags/feature-flag.repository.d.ts.map +1 -0
  8. package/dist/backend/featureFlags/feature-flag.service.d.ts +123 -0
  9. package/dist/backend/featureFlags/feature-flag.service.d.ts.map +1 -0
  10. package/dist/backend/featureFlags/index.d.ts +49 -0
  11. package/dist/backend/featureFlags/index.d.ts.map +1 -0
  12. package/dist/backend/index.d.ts +5 -0
  13. package/dist/backend/index.d.ts.map +1 -0
  14. package/dist/cache/index.d.ts +98 -0
  15. package/dist/cache/index.d.ts.map +1 -0
  16. package/dist/cache/strategies/memory.d.ts +103 -0
  17. package/dist/cache/strategies/memory.d.ts.map +1 -0
  18. package/dist/cache/strategies/redis.d.ts +105 -0
  19. package/dist/cache/strategies/redis.d.ts.map +1 -0
  20. package/dist/domain/featureFlags/index.d.ts +49 -0
  21. package/dist/domain/featureFlags/index.d.ts.map +1 -0
  22. package/dist/domain/featureFlags/provider.d.ts +166 -0
  23. package/dist/domain/featureFlags/provider.d.ts.map +1 -0
  24. package/dist/domain/featureFlags/providers/api.d.ts +78 -0
  25. package/dist/domain/featureFlags/providers/api.d.ts.map +1 -0
  26. package/dist/domain/featureFlags/providers/database.d.ts +102 -0
  27. package/dist/domain/featureFlags/providers/database.d.ts.map +1 -0
  28. package/dist/domain/featureFlags/providers/factory.d.ts +116 -0
  29. package/dist/domain/featureFlags/providers/factory.d.ts.map +1 -0
  30. package/dist/domain/featureFlags/providers/file.d.ts +84 -0
  31. package/dist/domain/featureFlags/providers/file.d.ts.map +1 -0
  32. package/dist/domain/featureFlags/providers/memory.d.ts +179 -0
  33. package/dist/domain/featureFlags/providers/memory.d.ts.map +1 -0
  34. package/dist/domain/featureFlags/providers/redis.d.ts +80 -0
  35. package/dist/domain/featureFlags/providers/redis.d.ts.map +1 -0
  36. package/dist/domain/index.d.ts +6 -0
  37. package/dist/domain/index.d.ts.map +1 -0
  38. package/dist/domain/types.d.ts +18 -0
  39. package/dist/domain/types.d.ts.map +1 -0
  40. package/dist/engine/featureFlags/engine.d.ts +193 -0
  41. package/dist/engine/featureFlags/engine.d.ts.map +1 -0
  42. package/dist/engine/featureFlags/index.d.ts +10 -0
  43. package/dist/engine/featureFlags/index.d.ts.map +1 -0
  44. package/dist/engine/index.d.ts +5 -0
  45. package/dist/engine/index.d.ts.map +1 -0
  46. package/dist/frontend/featureFlags/hooks/useFeatureFlag.d.ts +103 -0
  47. package/dist/frontend/featureFlags/hooks/useFeatureFlag.d.ts.map +1 -0
  48. package/dist/frontend/featureFlags/hooks/useFeatureFlagActions.d.ts +35 -0
  49. package/dist/frontend/featureFlags/hooks/useFeatureFlagActions.d.ts.map +1 -0
  50. package/dist/frontend/featureFlags/hooks/useFeatureFlagHelpers.d.ts +55 -0
  51. package/dist/frontend/featureFlags/hooks/useFeatureFlagHelpers.d.ts.map +1 -0
  52. package/dist/frontend/featureFlags/hooks/useFeatureFlagProvider.d.ts +57 -0
  53. package/dist/frontend/featureFlags/hooks/useFeatureFlagProvider.d.ts.map +1 -0
  54. package/dist/frontend/featureFlags/index.d.ts +14 -0
  55. package/dist/frontend/featureFlags/index.d.ts.map +1 -0
  56. package/dist/frontend/featureFlags/providers/FeatureFlagProvider.d.ts +99 -0
  57. package/dist/frontend/featureFlags/providers/FeatureFlagProvider.d.ts.map +1 -0
  58. package/dist/frontend/featureFlags/providers/FeatureFlagProviderHelpers.d.ts +45 -0
  59. package/dist/frontend/featureFlags/providers/FeatureFlagProviderHelpers.d.ts.map +1 -0
  60. package/dist/frontend/index.d.ts +2 -0
  61. package/dist/frontend/index.d.ts.map +1 -0
  62. package/dist/index.cjs +3951 -0
  63. package/dist/index.cjs.map +1 -0
  64. package/dist/index.d.ts +7 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.mjs +3902 -0
  67. package/dist/index.mjs.map +1 -0
  68. package/dist/utils/common/hash.d.ts +81 -0
  69. package/dist/utils/common/hash.d.ts.map +1 -0
  70. package/dist/utils/common/index.d.ts +11 -0
  71. package/dist/utils/common/index.d.ts.map +1 -0
  72. package/dist/utils/common/values.d.ts +48 -0
  73. package/dist/utils/common/values.d.ts.map +1 -0
  74. package/dist/utils/featureFlags/conditions.d.ts +114 -0
  75. package/dist/utils/featureFlags/conditions.d.ts.map +1 -0
  76. package/dist/utils/featureFlags/context.d.ts +241 -0
  77. package/dist/utils/featureFlags/context.d.ts.map +1 -0
  78. package/dist/utils/featureFlags/index.d.ts +11 -0
  79. package/dist/utils/featureFlags/index.d.ts.map +1 -0
  80. package/dist/utils/index.d.ts +6 -0
  81. package/dist/utils/index.d.ts.map +1 -0
  82. package/package.json +144 -0
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Memory Feature Flag Provider
3
+ *
4
+ * In-memory provider implementation that uses the FEATURES constant for flag data.
5
+ * This will be moved to @plyaz/core when the package structure is finalized.
6
+ *
7
+ * @fileoverview Memory provider implementation for feature flags
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlag, FeatureFlagRule, FeatureFlagConfig, FeatureFlagValue } from '@plyaz/types';
11
+ import { FeatureFlagProvider } from '../provider';
12
+ /**
13
+ * Memory-based feature flag provider that loads flags from the FEATURES constant.
14
+ *
15
+ * @class MemoryFeatureFlagProvider
16
+ * @extends {FeatureFlagProvider}
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const provider = new MemoryFeatureFlagProvider<FeatureFlagKey>({
21
+ * provider: 'memory',
22
+ * isCacheEnabled: false,
23
+ * isLoggingEnabled: true,
24
+ * }, FEATURES);
25
+ *
26
+ * await provider.initialize();
27
+ * const isEnabled = await provider.isEnabled('AUTH_GOOGLE');
28
+ * ```
29
+ */
30
+ export declare class MemoryFeatureFlagProvider<FeatureFlagKey extends string> extends FeatureFlagProvider<FeatureFlagKey> {
31
+ private flags;
32
+ private rules;
33
+ /**
34
+ * Creates a new memory feature flag provider.
35
+ *
36
+ * @param config - Provider configuration
37
+ * @param features - Record of feature flag keys to their default values
38
+ */
39
+ constructor(config: FeatureFlagConfig<FeatureFlagKey>, features: Record<FeatureFlagKey, FeatureFlagValue>);
40
+ /**
41
+ * Fetches flags and rules from memory (FEATURES constant).
42
+ *
43
+ * @protected
44
+ * @returns Promise resolving to flags and rules from memory
45
+ */
46
+ protected fetchData(): Promise<{
47
+ flags: FeatureFlag<FeatureFlagKey>[];
48
+ rules: FeatureFlagRule<FeatureFlagKey>[];
49
+ }>;
50
+ /**
51
+ * Creates a FeatureFlag object from a FEATURES constant entry.
52
+ *
53
+ * @private
54
+ * @param key - The feature flag key
55
+ * @param value - The value from FEATURES constant
56
+ * @param currentTime - Current timestamp
57
+ * @returns FeatureFlag object
58
+ */
59
+ private createFeatureFlagFromConstant;
60
+ /**
61
+ * Generates a human-readable name from a flag key.
62
+ *
63
+ * @private
64
+ * @param key - The feature flag key
65
+ * @returns Human-readable flag name
66
+ */
67
+ private generateFlagName;
68
+ /**
69
+ * Infers the flag type from its value.
70
+ *
71
+ * @private
72
+ * @param value - The flag value
73
+ * @returns The inferred type
74
+ */
75
+ private inferFlagType;
76
+ /**
77
+ * Gets manually added rules for memory provider.
78
+ *
79
+ * @private
80
+ * @returns Array of manually configured rules
81
+ */
82
+ private getManualRules;
83
+ /**
84
+ * Validates the memory provider configuration.
85
+ *
86
+ * @private
87
+ * @throws Error if configuration is invalid
88
+ */
89
+ private validateConfig;
90
+ /**
91
+ * Adds a rule to the memory provider at runtime.
92
+ *
93
+ * @param rule - The rule to add
94
+ */
95
+ addRule(rule: FeatureFlagRule<FeatureFlagKey>): void;
96
+ /**
97
+ * Removes a rule from the memory provider.
98
+ *
99
+ * @param ruleId - The ID of the rule to remove
100
+ */
101
+ removeRule(ruleId: string): void;
102
+ /**
103
+ * Updates a flag value in memory.
104
+ *
105
+ * @param key - The flag key to update
106
+ * @param value - The new value
107
+ * @param updateProps - Optional properties to update
108
+ */
109
+ updateFlag(key: FeatureFlagKey, value: FeatureFlagValue, updateProps?: Partial<Pick<FeatureFlag<FeatureFlagKey>, 'name' | 'description' | 'isEnabled' | 'environment' | 'rolloutPercentage' | 'type'>>): void;
110
+ /**
111
+ * Adds a new flag to memory at runtime.
112
+ *
113
+ * @param key - The flag key
114
+ * @param value - The flag value
115
+ * @param props - Optional flag properties
116
+ */
117
+ addFlag(key: FeatureFlagKey, value: FeatureFlagValue, props?: Partial<Pick<FeatureFlag<FeatureFlagKey>, 'name' | 'description' | 'isEnabled' | 'environment' | 'rolloutPercentage' | 'type'>>): void;
118
+ /**
119
+ * Checks if a flag with the given key exists.
120
+ */
121
+ private flagExists;
122
+ /**
123
+ * Creates a new flag object.
124
+ */
125
+ private createNewFlag;
126
+ /**
127
+ * Gets default properties for a new flag.
128
+ */
129
+ private getDefaultFlagProperties;
130
+ /**
131
+ * Merges default properties with user-provided properties.
132
+ */
133
+ private mergeWithUserProps;
134
+ /**
135
+ * Adds the flag to the store and notifies systems.
136
+ */
137
+ private addFlagToStore;
138
+ /**
139
+ * Removes a flag from memory.
140
+ *
141
+ * @param key - The flag key to remove
142
+ */
143
+ removeFlag(key: FeatureFlagKey): void;
144
+ /**
145
+ * Gets all current flags in memory.
146
+ *
147
+ * @returns Array of current flags
148
+ */
149
+ getCurrentFlags(): FeatureFlag<FeatureFlagKey>[];
150
+ /**
151
+ * Gets all current rules in memory.
152
+ *
153
+ * @returns Array of current rules
154
+ */
155
+ getCurrentRules(): FeatureFlagRule<FeatureFlagKey>[];
156
+ /**
157
+ * Resets the memory provider to its initial state.
158
+ */
159
+ reset(): Promise<void>;
160
+ /**
161
+ * Gets statistics about the memory provider.
162
+ *
163
+ * @returns Provider statistics
164
+ */
165
+ getStats(): {
166
+ flagCount: number;
167
+ ruleCount: number;
168
+ cacheSize: number;
169
+ subscriberCount: number;
170
+ isInitialized: boolean;
171
+ };
172
+ /**
173
+ * Logs messages with MemoryFeatureFlagProvider prefix.
174
+ *
175
+ * @param args - Arguments to log
176
+ */
177
+ protected log(...args: unknown[]): void;
178
+ }
179
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/domain/featureFlags/providers/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,yBAAyB,CACpC,cAAc,SAAS,MAAM,CAC7B,SAAQ,mBAAmB,CAAC,cAAc,CAAC;IAC3C,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,KAAK,CAAyC;IAEtD;;;;;OAKG;gBAED,MAAM,EAAE,iBAAiB,CAAC,cAAc,CAAC,EACzC,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAMpD;;;;;OAKG;cACa,SAAS,IAAI,OAAO,CAAC;QACnC,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,KAAK,EAAE,eAAe,CAAC,cAAc,CAAC,EAAE,CAAC;KAC1C,CAAC;IAyBF;;;;;;;;OAQG;IACH,OAAO,CAAC,6BAA6B;IAqBrC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,O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AAE,MAAM,CAAC;QACxB,aAAa,EAAE,OAAO,CAAC;KACxB;IAUD;;;;OAIG;IACH,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAKxC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Redis Feature Flag Provider
3
+ *
4
+ * Redis-based provider implementation supporting distributed caching and storage.
5
+ * This will be moved to @plyaz/core when the package structure is finalized.
6
+ *
7
+ * @fileoverview Redis provider implementation for feature flags
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlag, FeatureFlagRule, FeatureFlagConfig, FeatureFlagValue } from '@plyaz/types';
11
+ import { FeatureFlagProvider } from '../provider';
12
+ /**
13
+ * Redis-based feature flag provider supporting distributed caching and storage.
14
+ *
15
+ * @class RedisFeatureFlagProvider
16
+ * @extends {FeatureFlagProvider}
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const provider = new RedisFeatureFlagProvider<FeatureFlagKey>({
21
+ * provider: 'redis',
22
+ * redisConfig: {
23
+ * url: 'redis://localhost:6379',
24
+ * keyPrefix: 'feature_flags',
25
+ * },
26
+ * isCacheEnabled: true,
27
+ * cacheTtl: 300,
28
+ * }, FEATURES);
29
+ *
30
+ * await provider.initialize();
31
+ * const isEnabled = await provider.isEnabled('AUTH_GOOGLE');
32
+ * ```
33
+ */
34
+ export declare class RedisFeatureFlagProvider<FeatureFlagKey extends string> extends FeatureFlagProvider<FeatureFlagKey> {
35
+ /**
36
+ * Creates a new Redis feature flag provider.
37
+ *
38
+ * @param config - Provider configuration with Redis settings
39
+ * @param features - Record of feature flag keys to their default values
40
+ */
41
+ constructor(config: FeatureFlagConfig<FeatureFlagKey>, features: Record<FeatureFlagKey, FeatureFlagValue>);
42
+ /**
43
+ * Fetches flags and rules from Redis storage.
44
+ *
45
+ * @protected
46
+ * @returns Promise resolving to flags and rules from Redis
47
+ */
48
+ protected fetchData(): Promise<{
49
+ flags: FeatureFlag<FeatureFlagKey>[];
50
+ rules: FeatureFlagRule<FeatureFlagKey>[];
51
+ }>;
52
+ /**
53
+ * Validates the Redis provider configuration.
54
+ *
55
+ * @private
56
+ * @throws Error if configuration is invalid
57
+ */
58
+ private validateConfig;
59
+ /**
60
+ * Validates Redis URL format.
61
+ *
62
+ * @private
63
+ * @param url - URL to validate
64
+ * @returns True if valid Redis URL
65
+ */
66
+ private isValidRedisUrl;
67
+ /**
68
+ * Gets Redis provider information.
69
+ *
70
+ * @returns Redis provider status information
71
+ */
72
+ getRedisInfo(): {
73
+ url?: string;
74
+ keyPrefix?: string;
75
+ isImplemented: boolean;
76
+ requiredImplementation: string[];
77
+ recommendedPatterns: string[];
78
+ };
79
+ }
80
+ //# sourceMappingURL=redis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../src/domain/featureFlags/providers/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,wBAAwB,CACnC,cAAc,SAAS,MAAM,CAC7B,SAAQ,mBAAmB,CAAC,cAAc,CAAC;IAC3C;;;;;OAKG;gBAED,MAAM,EAAE,iBAAiB,CAAC,cAAc,CAAC,EACzC,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAOpD;;;;;OAKG;cACa,SAAS,IAAI,OAAO,CAAC;QACnC,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,KAAK,EAAE,eAAe,CAAC,cAAc,CAAC,EAAE,CAAC;KAC1C,CAAC;IAwCF;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAuBtB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;OAIG;IACH,YAAY,IAAI;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,OAAO,CAAC;QACvB,sBAAsB,EAAE,MAAM,EAAE,CAAC;QACjC,mBAAmB,EAAE,MAAM,EAAE,CAAC;KAC/B;CAoBF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Domain Layer Exports
3
+ */
4
+ export * from './featureFlags';
5
+ export type * from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,mBAAmB,SAAS,CAAC"}
@@ -0,0 +1,18 @@
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 { FeatureFlagValue } from '@plyaz/types';
11
+ import type { FEATURES } from '@plyaz/config';
12
+ /**
13
+ * Union type of all available feature flag keys.
14
+ * Automatically derived from the FEATURES constant for type safety.
15
+ */
16
+ export type FeatureFlagKey = keyof typeof FEATURES;
17
+ export type FeatureFlags = typeof FEATURES extends Record<FeatureFlagKey, FeatureFlagValue> ? typeof FEATURES : never;
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/domain/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,QAAQ,CAAC;AAEnD,MAAM,MAAM,YAAY,GACtB,OAAO,QAAQ,SAAS,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,OAAO,QAAQ,GAAG,KAAK,CAAC"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Feature Flag Evaluation Engine
3
+ *
4
+ * Core engine for evaluating feature flags with rules, targeting, and rollouts.
5
+ * This will be moved to @plyaz/core when the package structure is finalized.
6
+ *
7
+ * @fileoverview Core feature flag evaluation engine
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlag, FeatureFlagRule, FeatureFlagContext, FeatureFlagEvaluation, FeatureFlagValue } from '@plyaz/types';
11
+ /**
12
+ * Core feature flag evaluation engine.
13
+ * Handles all the logic for evaluating feature flags including rules, targeting, and rollouts.
14
+ *
15
+ * @class FeatureFlagEngine
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const engine = new FeatureFlagEngine(defaultFlags, true);
20
+ * engine.setFlags(flagsFromDatabase);
21
+ * engine.setRules(rulesFromDatabase);
22
+ *
23
+ * const evaluation = engine.evaluate('AUTH_GOOGLE', context);
24
+ * console.log(evaluation.isEnabled); // true/false
25
+ * ```
26
+ */
27
+ export declare class FeatureFlagEngine<FeatureFlagKey extends string> {
28
+ private defaults;
29
+ private isLoggingEnabled;
30
+ /** Storage for active feature flags */
31
+ private flags;
32
+ /** Storage for targeting rules, organized by flag key */
33
+ private rules;
34
+ /** Storage for manual overrides (useful for testing) */
35
+ private overrides;
36
+ /**
37
+ * Creates a new feature flag evaluation engine.
38
+ *
39
+ * @param defaults - Default flag values to fall back to
40
+ * @param isLoggingEnabled - Whether to enable debug logging
41
+ */
42
+ constructor(defaults: Record<FeatureFlagKey, FeatureFlagValue>, isLoggingEnabled?: boolean);
43
+ /**
44
+ * Sets the active feature flags for evaluation.
45
+ * Clears existing flags and rules before setting new ones.
46
+ *
47
+ * @param flags - Array of feature flags to activate
48
+ */
49
+ setFlags(flags: FeatureFlag<FeatureFlagKey>[]): void;
50
+ /**
51
+ * Sets the targeting rules for feature flags.
52
+ * Rules are automatically sorted by priority (higher numbers first).
53
+ *
54
+ * @param rules - Array of feature flag rules
55
+ */
56
+ setRules(rules: FeatureFlagRule<FeatureFlagKey>[]): void;
57
+ /**
58
+ * Sets a manual override for a specific flag.
59
+ * Overrides take precedence over all other evaluation logic.
60
+ *
61
+ * @param key - The flag key to override
62
+ * @param value - The value to force for this flag
63
+ */
64
+ setOverride(key: FeatureFlagKey, value: FeatureFlagValue): void;
65
+ /**
66
+ * Removes a manual override for a specific flag.
67
+ *
68
+ * @param key - The flag key to remove override for
69
+ */
70
+ removeOverride(key: FeatureFlagKey): void;
71
+ /**
72
+ * Clears all manual overrides.
73
+ */
74
+ clearOverrides(): void;
75
+ /**
76
+ * Gets all current flags.
77
+ *
78
+ * @returns Array of all feature flags
79
+ */
80
+ getFlags(): FeatureFlag<FeatureFlagKey>[];
81
+ /**
82
+ * Evaluates a feature flag and returns the complete evaluation result.
83
+ *
84
+ * @param key - The feature flag key to evaluate
85
+ * @param context - Optional context for targeting
86
+ * @returns Complete evaluation result with value and metadata
87
+ */
88
+ evaluate(key: FeatureFlagKey, context?: FeatureFlagContext): FeatureFlagEvaluation<FeatureFlagKey>;
89
+ /**
90
+ * Checks for manual override and returns evaluation if found.
91
+ *
92
+ * @private
93
+ * @param key - The feature flag key
94
+ * @param evaluatedAt - Evaluation timestamp
95
+ * @returns Evaluation result or null if no override
96
+ */
97
+ private checkOverride;
98
+ /**
99
+ * Creates default evaluation result.
100
+ *
101
+ * @private
102
+ * @param key - The feature flag key
103
+ * @param evaluatedAt - Evaluation timestamp
104
+ * @returns Default evaluation result
105
+ */
106
+ private createDefaultEvaluation;
107
+ /**
108
+ * Creates disabled evaluation result.
109
+ *
110
+ * @private
111
+ * @param key - The feature flag key
112
+ * @param evaluatedAt - Evaluation timestamp
113
+ * @returns Disabled evaluation result
114
+ */
115
+ private createDisabledEvaluation;
116
+ /**
117
+ * Creates flag evaluation result.
118
+ *
119
+ * @private
120
+ * @param key - The feature flag key
121
+ * @param flag - The feature flag
122
+ * @param evaluatedAt - Evaluation timestamp
123
+ * @returns Flag evaluation result
124
+ */
125
+ private createFlagEvaluation;
126
+ /**
127
+ * Checks if environment matches for flag evaluation.
128
+ *
129
+ * @private
130
+ * @param flag - The feature flag
131
+ * @param context - Evaluation context
132
+ * @returns true if environment matches
133
+ */
134
+ private isEnvironmentMatch;
135
+ /**
136
+ * Checks if user is in flag-level rollout.
137
+ *
138
+ * @private
139
+ * @param key - The feature flag key
140
+ * @param flag - The feature flag
141
+ * @param context - Evaluation context
142
+ * @returns true if user is in rollout
143
+ */
144
+ private isInFlagRollout;
145
+ /**
146
+ * Evaluates all rules for a flag.
147
+ *
148
+ * @private
149
+ * @param key - The feature flag key
150
+ * @param context - Evaluation context
151
+ * @param evaluatedAt - Evaluation timestamp
152
+ * @returns Rule evaluation result or null if no match
153
+ */
154
+ private evaluateRules;
155
+ /**
156
+ * Evaluates a single matching rule and returns result if it passes.
157
+ *
158
+ * @private
159
+ * @param key - The feature flag key
160
+ * @param rule - The rule to evaluate
161
+ * @param context - Evaluation context
162
+ * @param evaluatedAt - Evaluation timestamp
163
+ * @returns Rule evaluation result or null if no match
164
+ */
165
+ private evaluateMatchingRule;
166
+ /**
167
+ * Evaluates a single rule against the provided context.
168
+ * All conditions in the rule must match (AND logic).
169
+ *
170
+ * @private
171
+ * @param rule - The rule to evaluate
172
+ * @param context - Context to evaluate against
173
+ * @returns true if the rule matches the context
174
+ */
175
+ private evaluateRule;
176
+ /**
177
+ * Evaluates a single condition against the provided context.
178
+ *
179
+ * @private
180
+ * @param condition - The condition to evaluate
181
+ * @param context - Context to evaluate against
182
+ * @returns true if the condition matches
183
+ */
184
+ private evaluateCondition;
185
+ /**
186
+ * Logs debug information if logging is enabled.
187
+ *
188
+ * @private
189
+ * @param args - Arguments to log
190
+ */
191
+ private log;
192
+ }
193
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.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AC,wBAAwB;IAahC;;;;;;;;OAQG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAUvB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAiBrB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAwB5B;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAYzB;;;;;OAKG;IACH,OAAO,CAAC,GAAG;CAKZ"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Feature Flags Engine - Main Exports
3
+ *
4
+ * Exports the feature flag evaluation engine.
5
+ *
6
+ * @fileoverview Feature flags engine exports
7
+ * @version 1.0.0
8
+ */
9
+ export { FeatureFlagEngine } from './engine';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/engine/featureFlags/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Engine Layer Exports
3
+ */
4
+ export * from './featureFlags';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * useFeatureFlag Hook
3
+ *
4
+ * React hook for accessing individual feature flags with caching and real-time updates.
5
+ * This will be moved to @plyaz/core when the package structure is finalized.
6
+ *
7
+ * @fileoverview React hook for feature flag access
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlagValue, FeatureFlagHook, UseFeatureFlagOptions } from '@plyaz/types';
11
+ /**
12
+ * React hook for accessing a single feature flag.
13
+ * Provides real-time updates and automatic caching.
14
+ *
15
+ * @template T - Expected type of the flag value
16
+ * @param key - Feature flag key to evaluate
17
+ * @param options - Hook configuration options
18
+ * @returns Feature flag hook state
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Basic usage
23
+ * const { value: isEnabled, isLoading, error } = useFeatureFlag<FeatureFlagKey>('AUTH_GOOGLE');
24
+ *
25
+ * // With context and type safety
26
+ * const { value, isLoading, refresh } = useFeatureFlag<FeatureFlagKey, number>(
27
+ * 'ROLLOUT_PERCENTAGE',
28
+ * {
29
+ * context: { userId: 'user123', environment: 'production' },
30
+ * defaultValue: 0
31
+ * }
32
+ * );
33
+ *
34
+ * // With auto-refresh disabled
35
+ * const { value, refresh } = useFeatureFlag<FeatureFlagKey>('BETA_FEATURE', {
36
+ * autoRefresh: false,
37
+ * defaultValue: false
38
+ * });
39
+ * ```
40
+ */
41
+ export declare function useFeatureFlag<FeatureFlagKey extends string, T extends FeatureFlagValue = boolean>(key: FeatureFlagKey, options?: UseFeatureFlagOptions): FeatureFlagHook<T>;
42
+ /**
43
+ * Hook for checking if a feature flag is enabled.
44
+ * Simplified version of useFeatureFlag that returns only boolean state.
45
+ *
46
+ * @param key - Feature flag key to check
47
+ * @param options - Hook configuration options
48
+ * @returns Boolean indicating if flag is enabled
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const isGoogleAuthEnabled = useFeatureFlagEnabled<FeatureFlagKey>('AUTH_GOOGLE');
53
+ * const isBetaEnabled = useFeatureFlagEnabled<FeatureFlagKey>('BETA_FEATURE', {
54
+ * context: { userId: 'user123', environment: 'production' }
55
+ * });
56
+ * ```
57
+ */
58
+ export declare function useFeatureFlagEnabled<FeatureFlagKey extends string>(key: FeatureFlagKey, options?: UseFeatureFlagOptions): boolean;
59
+ /**
60
+ * Hook for getting a feature flag value with type safety.
61
+ * Provides the raw value without the loading state wrapper.
62
+ *
63
+ * @template T - Expected type of the flag value
64
+ * @param key - Feature flag key to get value for
65
+ * @param options - Hook configuration options
66
+ * @returns The flag value with type safety
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const rolloutPercentage = useFeatureFlagValue<FeatureFlagKey, number>('ROLLOUT_PERCENTAGE', {
71
+ * defaultValue: 0
72
+ * });
73
+ *
74
+ * const theme = useFeatureFlagValue<FeatureFlagKey, 'light' | 'dark'>('UI_THEME', {
75
+ * defaultValue: 'light'
76
+ * });
77
+ * ```
78
+ */
79
+ export declare function useFeatureFlagValue<FeatureFlagKey extends string, T extends FeatureFlagValue = FeatureFlagValue>(key: FeatureFlagKey, options?: UseFeatureFlagOptions): T;
80
+ /**
81
+ * Hook for evaluating multiple feature flags at once.
82
+ * Useful for loading multiple flags with a single provider call.
83
+ *
84
+ * @param keys - Array of feature flag keys to evaluate
85
+ * @param options - Hook configuration options
86
+ * @returns Map of flag keys to their hook states
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const flags = useMultipleFeatureFlags<FeatureFlagKey>([
91
+ * 'AUTH_GOOGLE',
92
+ * 'AUTH_GITHUB',
93
+ * 'BETA_FEATURE'
94
+ * ], {
95
+ * context: { userId: 'user123', environment: 'production' }
96
+ * });
97
+ *
98
+ * const isGoogleEnabled = flags.AUTH_GOOGLE.value;
99
+ * const isGithubEnabled = flags.AUTH_GITHUB.value;
100
+ * ```
101
+ */
102
+ export declare function useMultipleFeatureFlags<FeatureFlagKey extends string>(keys: FeatureFlagKey[], options?: UseFeatureFlagOptions): Record<FeatureFlagKey, FeatureFlagHook<FeatureFlagValue>>;
103
+ //# sourceMappingURL=useFeatureFlag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFeatureFlag.d.ts","sourceRoot":"","sources":["../../../../src/frontend/featureFlags/hooks/useFeatureFlag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAO7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,cAAc,CAAC,cAAc,SAAS,MAAM,EAAE,CAAC,SAAS,gBAAgB,GAAG,OAAO,EAChG,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,qBAA0B,GAClC,eAAe,CAAC,CAAC,CAAC,CA8CpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,SAAS,MAAM,EACjE,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAOT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,SAAS,MAAM,EAC7B,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EAC7C,GAAG,EAAE,cAAc,EAAE,OAAO,GAAE,qBAA0B,GAAG,CAAC,CAG7D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,cAAc,SAAS,MAAM,EACnE,IAAI,EAAE,cAAc,EAAE,EACtB,OAAO,GAAE,qBAA0B,GAClC,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAuB3D"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * useFeatureFlagHelpers Hook
3
+ *
4
+ * React hook providing helper functions for feature flag management.
5
+ * This will be moved to @plyaz/core when the package structure is finalized.
6
+ *
7
+ * @fileoverview Helper functions hook for feature flags
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlagHelpers } from '@plyaz/types';
11
+ /**
12
+ * Hook that provides helper functions for feature flag operations.
13
+ * Includes override management, bulk operations, and conditional execution.
14
+ *
15
+ * @returns Object containing helper functions
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const helpers = useFeatureFlagHelpers<FeatureFlagKey>();
20
+ *
21
+ * // Set override
22
+ * helpers.setOverride('AUTH_GOOGLE', true);
23
+ *
24
+ * // Check multiple flags
25
+ * const anyEnabled = await helpers.isAnyEnabled(['AUTH_GOOGLE', 'AUTH_GITHUB']);
26
+ *
27
+ * // Conditional execution
28
+ * const result = await helpers.whenEnabled('BETA_FEATURE',
29
+ * () => console.log('Beta feature is enabled'),
30
+ * () => console.log('Beta feature is disabled')
31
+ * );
32
+ * ```
33
+ */
34
+ export declare function useFeatureFlagHelpers<FeatureFlagKey extends string>(): FeatureFlagHelpers<FeatureFlagKey>;
35
+ //# sourceMappingURL=useFeatureFlagActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFeatureFlagActions.d.ts","sourceRoot":"","sources":["../../../../src/frontend/featureFlags/hooks/useFeatureFlagActions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAwC,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAG7F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,SAAS,MAAM,KAC1B,kBAAkB,CAAC,cAAc,CAAC,CAsGtC"}