@plyaz/types 1.19.4 → 1.19.5

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 (49) hide show
  1. package/dist/api/index.cjs +29 -0
  2. package/dist/api/index.cjs.map +1 -1
  3. package/dist/api/index.js +29 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/core/auth/types.d.ts +1 -1
  6. package/dist/core/domain/index.d.ts +5 -0
  7. package/dist/core/domain/types.d.ts +123 -0
  8. package/dist/core/events/enums.d.ts +25 -1
  9. package/dist/core/events/index.d.ts +3 -3
  10. package/dist/core/events/payloads.d.ts +80 -1
  11. package/dist/core/featureFlag/types.d.ts +16 -16
  12. package/dist/core/frontend/featureFlags.d.ts +106 -0
  13. package/dist/core/frontend/index.d.ts +6 -0
  14. package/dist/core/frontend/types.d.ts +318 -0
  15. package/dist/core/index.d.ts +6 -2
  16. package/dist/core/init/index.d.ts +5 -0
  17. package/dist/core/init/types.d.ts +347 -0
  18. package/dist/core/modules.d.ts +19 -3
  19. package/dist/core/services/index.d.ts +5 -0
  20. package/dist/core/{services.d.ts → services/types.d.ts} +74 -6
  21. package/dist/errors/codes.d.ts +3 -0
  22. package/dist/errors/index.cjs +29 -0
  23. package/dist/errors/index.cjs.map +1 -1
  24. package/dist/errors/index.d.ts +2 -0
  25. package/dist/errors/index.js +29 -0
  26. package/dist/errors/index.js.map +1 -1
  27. package/dist/errors/middleware.d.ts +105 -0
  28. package/dist/errors/store.d.ts +140 -0
  29. package/dist/examples/index.d.ts +1 -1
  30. package/dist/examples/types.d.ts +64 -0
  31. package/dist/features/feature-flag/dto.types.d.ts +67 -0
  32. package/dist/features/feature-flag/index.d.ts +3 -0
  33. package/dist/features/feature-flag/service.types.d.ts +184 -0
  34. package/dist/features/feature-flag/store.types.d.ts +166 -0
  35. package/dist/features/feature-flag/types.d.ts +16 -4
  36. package/dist/globals.d.ts +23 -0
  37. package/dist/index.cjs +49 -0
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.js +49 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/store/index.cjs +13 -0
  42. package/dist/store/index.cjs.map +1 -1
  43. package/dist/store/index.d.ts +2 -0
  44. package/dist/store/index.js +11 -0
  45. package/dist/store/index.js.map +1 -1
  46. package/dist/store/keys.d.ts +23 -0
  47. package/dist/store/types.d.ts +62 -71
  48. package/dist/testing/features/feature-flags/types.d.ts +3 -3
  49. package/package.json +6 -2
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Middleware Types
3
+ *
4
+ * Type definitions for error middleware across frontend and backend.
5
+ * Used by @plyaz/errors middleware implementations.
6
+ */
7
+ import type { Request, Response } from 'express';
8
+ import type { SerializedError, ErrorStoreActions } from './store';
9
+ import type { ErrorEventFactory, ErrorResponse } from './types';
10
+ /**
11
+ * Configuration for HTTP error handler middleware.
12
+ * Used by Express and NestJS error handlers.
13
+ */
14
+ export interface HttpErrorHandlerConfig {
15
+ /** Global error handler instance (optional - for tracking) */
16
+ errorHandler?: GlobalErrorHandler;
17
+ /** Include stack traces in response (default: false) */
18
+ includeStack?: boolean;
19
+ /** Custom error formatter */
20
+ formatError?: (error: SerializedError, req: Request) => ErrorResponse;
21
+ /** Callback when error is handled */
22
+ onError?: (error: SerializedError, req: Request, res: Response) => void;
23
+ /** Log errors to console (default: true) */
24
+ logErrors?: boolean;
25
+ }
26
+ /**
27
+ * Configuration for the global error handler.
28
+ * Used to initialize error capturing for uncaught errors and rejections.
29
+ */
30
+ export interface GlobalErrorHandlerConfig {
31
+ /** Source identifier for errors (default: 'global') */
32
+ source?: string;
33
+ /** Maximum errors to keep (default: 100) */
34
+ maxErrors?: number;
35
+ /** Filter function - return false to ignore error */
36
+ filter?: (error: unknown) => boolean;
37
+ /** Custom serializer */
38
+ serialize?: (error: unknown, source?: string) => SerializedError;
39
+ /** Callback after error is added to store */
40
+ onError?: (error: SerializedError) => void;
41
+ /** Also log to console (default: true in dev) */
42
+ logToConsole?: boolean;
43
+ }
44
+ /**
45
+ * Global error handler instance interface.
46
+ * Provides methods to capture errors and manage the error store.
47
+ */
48
+ export interface GlobalErrorHandler {
49
+ /** Manually capture an error */
50
+ captureError: (error: unknown, source?: string) => void;
51
+ /** Manually capture an exception (alias) */
52
+ captureException: (error: unknown, source?: string) => void;
53
+ /** Get the error store */
54
+ getStore: () => ErrorStoreActions;
55
+ /** Cleanup and remove listeners */
56
+ destroy: () => void;
57
+ }
58
+ /**
59
+ * Configuration for backend error store.
60
+ * Used to create in-memory error stores for server environments.
61
+ */
62
+ export interface BackendErrorStoreConfig {
63
+ /** Maximum errors to keep in memory (default: 100) */
64
+ maxErrors?: number;
65
+ /** Callback when an error is added */
66
+ onErrorAdded?: (error: SerializedError) => void;
67
+ /** Callback when errors are cleared */
68
+ onErrorsCleared?: () => void;
69
+ }
70
+ /**
71
+ * Backend error store interface.
72
+ * Extends ErrorStoreActions with backend-specific getters.
73
+ */
74
+ export interface BackendErrorStore extends ErrorStoreActions {
75
+ /** Get all errors (backend-specific method) */
76
+ getErrors(): SerializedError[];
77
+ /** Get last error (backend-specific method) */
78
+ getLastError(): SerializedError | null;
79
+ /** Get error count (backend-specific method) */
80
+ getErrorCount(): number;
81
+ /** Get active error count (backend-specific method) */
82
+ getActiveErrorCount(): number;
83
+ /** Check if connected (backend-specific method) */
84
+ getIsConnected(): boolean;
85
+ }
86
+ /**
87
+ * Keys for backend error store action methods.
88
+ */
89
+ export type BackendErrorStoreActionKeys = 'addError' | 'removeError' | 'clearErrors' | 'clearErrorsByCategory' | 'clearErrorsBySource' | 'dismissError' | 'dismissAllErrors' | 'setConnected' | 'reset';
90
+ /**
91
+ * Keys for backend error store getter methods.
92
+ */
93
+ export type BackendErrorStoreGetterKeys = 'getErrors' | 'getLastError' | 'getErrorCount' | 'getActiveErrorCount' | 'getIsConnected';
94
+ /**
95
+ * Event integration interface for error event emission.
96
+ * Allows errors to be listened to via scoped-error-events.
97
+ */
98
+ export interface ErrorEventIntegration {
99
+ /** Emit an error event that can be listened to */
100
+ emitError(error: SerializedError): void;
101
+ /** Emit an error event with custom event name */
102
+ emitErrorEvent(eventName: string, error: SerializedError): void;
103
+ /** Get the event factory for custom integration */
104
+ getEventFactory(): ErrorEventFactory;
105
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Error Store Types
3
+ *
4
+ * Type definitions for the unified error store slice.
5
+ * Used by @plyaz/store and error middleware.
6
+ */
7
+ import type { ERROR_CATEGORY, ERROR_SEVERITY } from './enums';
8
+ import type { ERROR_CODES } from './codes';
9
+ /**
10
+ * Serialized error for store state.
11
+ * JSON-serializable version of PackageErrorLike.
12
+ */
13
+ export interface SerializedError {
14
+ /** Unique ID for this error instance */
15
+ id: string;
16
+ /** Error code (from ERROR_CODES) */
17
+ code: (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
18
+ /** Human-readable error message */
19
+ message: string;
20
+ /** HTTP status code */
21
+ status?: number;
22
+ /** Error category */
23
+ category: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
24
+ /** Error severity */
25
+ severity?: (typeof ERROR_SEVERITY)[keyof typeof ERROR_SEVERITY];
26
+ /** Correlation ID for tracing */
27
+ correlationId?: string;
28
+ /** ISO timestamp when error occurred */
29
+ timestamp: string;
30
+ /** Whether error is retryable */
31
+ isRetryable: boolean;
32
+ /** Additional context (JSON-serializable) */
33
+ context?: Record<string, unknown>;
34
+ /** User-friendly message */
35
+ userMessage?: string;
36
+ /** Source/namespace of the error */
37
+ source?: string;
38
+ /** Whether error has been dismissed by user */
39
+ dismissed?: boolean;
40
+ }
41
+ /**
42
+ * Error store state shape.
43
+ */
44
+ export interface ErrorStoreState {
45
+ /** Array of all errors (newest first) */
46
+ errors: SerializedError[];
47
+ /** Most recent error */
48
+ lastError: SerializedError | null;
49
+ /** Total error count (including dismissed) */
50
+ errorCount: number;
51
+ /** Count of undismissed errors */
52
+ activeErrorCount: number;
53
+ /** Whether error middleware is connected */
54
+ isConnected: boolean;
55
+ }
56
+ /**
57
+ * Error store actions.
58
+ */
59
+ export interface ErrorStoreActions {
60
+ /** Add an error to the store */
61
+ addError: (error: SerializedError) => void;
62
+ /** Remove an error by ID */
63
+ removeError: (id: string) => void;
64
+ /** Clear all errors */
65
+ clearErrors: () => void;
66
+ /** Clear errors by category */
67
+ clearErrorsByCategory: (category: string) => void;
68
+ /** Clear errors by source */
69
+ clearErrorsBySource: (source: string) => void;
70
+ /** Dismiss an error (mark as read) */
71
+ dismissError: (id: string) => void;
72
+ /** Dismiss all errors */
73
+ dismissAllErrors: () => void;
74
+ /** Set connection status */
75
+ setConnected: (connected: boolean) => void;
76
+ /** Reset store to initial state */
77
+ reset: () => void;
78
+ }
79
+ /**
80
+ * Complete error store slice (state + actions).
81
+ */
82
+ export interface ErrorStoreSlice extends ErrorStoreState, ErrorStoreActions {
83
+ }
84
+ /**
85
+ * Error store selectors interface.
86
+ */
87
+ export interface ErrorStoreSelectors {
88
+ /** Select all errors */
89
+ selectErrors: (state: ErrorStoreState) => SerializedError[];
90
+ /** Select active (undismissed) errors */
91
+ selectActiveErrors: (state: ErrorStoreState) => SerializedError[];
92
+ /** Select errors by category */
93
+ selectErrorsByCategory: (state: ErrorStoreState, category: string) => SerializedError[];
94
+ /** Select errors by source */
95
+ selectErrorsBySource: (state: ErrorStoreState, source: string) => SerializedError[];
96
+ /** Select errors by severity */
97
+ selectErrorsBySeverity: (state: ErrorStoreState, severity: string) => SerializedError[];
98
+ /** Select retryable errors */
99
+ selectRetryableErrors: (state: ErrorStoreState) => SerializedError[];
100
+ /** Select last error */
101
+ selectLastError: (state: ErrorStoreState) => SerializedError | null;
102
+ /** Select error count */
103
+ selectErrorCount: (state: ErrorStoreState) => number;
104
+ /** Select active error count */
105
+ selectActiveErrorCount: (state: ErrorStoreState) => number;
106
+ /** Check if has errors */
107
+ selectHasErrors: (state: ErrorStoreState) => boolean;
108
+ /** Check if has active errors */
109
+ selectHasActiveErrors: (state: ErrorStoreState) => boolean;
110
+ }
111
+ /**
112
+ * Error middleware configuration.
113
+ */
114
+ export interface ErrorMiddlewareConfig {
115
+ /** Maximum errors to keep in store (default: 100) */
116
+ maxErrors?: number;
117
+ /** Error namespaces to subscribe to (default: ['global']) */
118
+ namespaces?: string[];
119
+ /** Error scopes to listen on (default: ['GLOBAL']) */
120
+ scopes?: ('GLOBAL' | 'CONFIG' | 'CLIENT' | 'REQUEST')[];
121
+ /** Filter function to decide which errors to store */
122
+ filter?: (error: unknown) => boolean;
123
+ /** Source identifier for errors from this middleware */
124
+ source?: string;
125
+ /** Auto-connect on creation (default: true) */
126
+ autoConnect?: boolean;
127
+ }
128
+ /**
129
+ * Error middleware instance interface.
130
+ */
131
+ export interface ErrorMiddleware {
132
+ /** Connect and start listening to errors */
133
+ connect: () => void;
134
+ /** Disconnect and stop listening */
135
+ disconnect: () => void;
136
+ /** Whether middleware is connected */
137
+ readonly isConnected: boolean;
138
+ /** Get current configuration */
139
+ readonly config: ErrorMiddlewareConfig;
140
+ }
@@ -14,4 +14,4 @@
14
14
  * ```
15
15
  */
16
16
  export { CreateExampleSchema, UpdateExampleSchema, PatchExampleSchema, QueryExampleSchema, DeleteExampleSchema, ExampleResponseSchema, ExampleListResponseSchema, } from './schemas';
17
- export type { CreateExampleDTO, UpdateExampleDTO, PatchExampleDTO, QueryExampleDTO, DeleteExampleDTO, ExampleResponseDTO, ExampleListResponseDTO, ExampleEntity, ExampleStoreItem, ExampleStoreState, ExampleCreatedPayload, ExampleUpdatedPayload, ExampleDeletedPayload, ExampleValidationFailedPayload, } from './types';
17
+ export type { CreateExampleDTO, UpdateExampleDTO, PatchExampleDTO, QueryExampleDTO, DeleteExampleDTO, ExampleResponseDTO, ExampleListResponseDTO, ExampleEntity, ExampleStoreItem, ExampleStoreState, ExampleCreatedPayload, ExampleUpdatedPayload, ExampleDeletedPayload, ExampleValidationFailedPayload, ExampleFrontendStoreData, ExampleFrontendStore, ExampleFrontendServiceConfig, ExampleFrontendEventType, ExampleUser, ExampleDomainServiceConfig, } from './types';
@@ -7,6 +7,9 @@
7
7
  import type { z } from 'zod';
8
8
  import type { CreateExampleSchema, UpdateExampleSchema, PatchExampleSchema, QueryExampleSchema, DeleteExampleSchema, ExampleResponseSchema, ExampleListResponseSchema } from './schemas';
9
9
  import type { CoreEntityCreatedPayload, CoreEntityUpdatedPayload, CoreEntityDeletedPayload, CoreValidationFailedPayload } from '../core/events';
10
+ import type { CoreBaseFrontendStore, CoreBaseFrontendServiceConfig } from '../core/frontend';
11
+ import type { CoreServiceInitConfig } from '../core/init';
12
+ import type { CoreBaseDomainServiceConfig } from '../core/domain';
10
13
  /**
11
14
  * Create request DTO (POST body)
12
15
  */
@@ -101,3 +104,64 @@ export type ExampleDeletedPayload = CoreEntityDeletedPayload;
101
104
  * Event payload for example:validation:failed
102
105
  */
103
106
  export type ExampleValidationFailedPayload = CoreValidationFailedPayload;
107
+ /**
108
+ * Example frontend store data type
109
+ */
110
+ export interface ExampleFrontendStoreData {
111
+ items: ExampleEntity[];
112
+ selectedId: string | null;
113
+ }
114
+ /**
115
+ * Example frontend store interface (Zustand-compatible)
116
+ */
117
+ export interface ExampleFrontendStore extends CoreBaseFrontendStore<ExampleFrontendStoreData> {
118
+ items: ExampleEntity[];
119
+ selectedId: string | null;
120
+ isLoading: boolean;
121
+ error: Error | null;
122
+ setData(data: ExampleFrontendStoreData): void;
123
+ updateData?(data: Partial<ExampleFrontendStoreData>): void;
124
+ setLoading(isLoading: boolean): void;
125
+ setError(error: unknown): void;
126
+ setItems(items: ExampleEntity[]): void;
127
+ addItem(item: ExampleEntity): void;
128
+ updateItem(id: string, updates: Partial<ExampleEntity>): void;
129
+ removeItem(id: string): void;
130
+ selectItem(id: string | null): void;
131
+ clearError(): void;
132
+ }
133
+ /**
134
+ * Example Frontend Service Configuration
135
+ */
136
+ export interface ExampleFrontendServiceConfig extends CoreBaseFrontendServiceConfig<ExampleFrontendStoreData, ExampleFrontendStore>, CoreServiceInitConfig {
137
+ /** API base path for example endpoints */
138
+ apiBasePath?: string;
139
+ /** Auto-fetch on initialization */
140
+ autoFetch?: boolean;
141
+ /** Polling interval in ms (0 = disabled) */
142
+ pollingInterval?: number;
143
+ }
144
+ /**
145
+ * Example frontend event types
146
+ */
147
+ export type ExampleFrontendEventType = 'example:fetching' | 'example:fetched' | 'example:fetch:error' | 'example:creating' | 'example:created' | 'example:create:error' | 'example:updating' | 'example:updated' | 'example:update:error' | 'example:deleting' | 'example:deleted' | 'example:delete:error' | 'example:store:synced';
148
+ /**
149
+ * Example User entity for backend repository
150
+ */
151
+ export interface ExampleUser extends Record<string, unknown> {
152
+ id: string;
153
+ email: string;
154
+ name: string;
155
+ created_at?: string;
156
+ updated_at?: string;
157
+ deleted_at?: string | null;
158
+ }
159
+ /**
160
+ * Example Domain Service Configuration
161
+ */
162
+ export interface ExampleDomainServiceConfig extends CoreBaseDomainServiceConfig, CoreServiceInitConfig {
163
+ /** Use real API client instead of mocks */
164
+ useRealApi?: boolean;
165
+ /** API base path for example endpoints */
166
+ apiBasePath?: string;
167
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Feature Flag DTO Types
3
+ *
4
+ * Data Transfer Object types for API communication.
5
+ * These represent the wire format (snake_case) that the API uses.
6
+ *
7
+ * @fileoverview Feature flag API DTO type definitions
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlagValue } from './types';
11
+ /**
12
+ * API Response DTO for a single feature flag
13
+ */
14
+ export interface FeatureFlagResponseDTO {
15
+ key: string;
16
+ value: FeatureFlagValue;
17
+ name: string;
18
+ description?: string;
19
+ is_enabled: boolean;
20
+ type: 'boolean' | 'string' | 'number' | 'json';
21
+ environment: string;
22
+ rollout_percentage?: number;
23
+ rules?: FeatureFlagRuleDTO[];
24
+ metadata?: Record<string, unknown>;
25
+ tags?: string[];
26
+ created_at: string;
27
+ updated_at: string;
28
+ created_by: string;
29
+ updated_by: string;
30
+ }
31
+ /**
32
+ * API Response DTO for a feature flag rule
33
+ */
34
+ export interface FeatureFlagRuleDTO {
35
+ id: string;
36
+ name: string;
37
+ flag_key: string;
38
+ conditions: Array<{
39
+ field: string;
40
+ operator: string;
41
+ value: string | number | string[] | number[];
42
+ }>;
43
+ value: FeatureFlagValue;
44
+ priority: number;
45
+ is_enabled: boolean;
46
+ rollout_percentage?: number;
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ /**
50
+ * API Response DTO for evaluation result
51
+ */
52
+ export interface FeatureFlagEvaluationDTO {
53
+ key: string;
54
+ value: FeatureFlagValue;
55
+ is_enabled: boolean;
56
+ reason: 'default' | 'rule_match' | 'rollout' | 'override' | 'disabled';
57
+ source?: 'default' | 'override' | 'rule' | 'rollout';
58
+ matched_rule_id?: string;
59
+ evaluated_at: string;
60
+ }
61
+ /**
62
+ * API Response for fetching all flags
63
+ */
64
+ export interface FetchAllFlagsResponseDTO {
65
+ flags: FeatureFlagResponseDTO[];
66
+ rules?: FeatureFlagRuleDTO[];
67
+ }
@@ -1 +1,4 @@
1
1
  export type * from './types';
2
+ export type * from './store.types';
3
+ export type * from './service.types';
4
+ export type * from './dto.types';
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Service Flag Requirement Types
3
+ *
4
+ * Type definitions for services that depend on feature flags.
5
+ * Enables declarative flag dependencies per service.
6
+ *
7
+ * @fileoverview Service flag requirement type definitions
8
+ * @version 1.0.0
9
+ */
10
+ import type { FeatureFlagContext, FeatureFlagProvider, FeatureFlagConfig, FeatureFlagValue } from './types';
11
+ import type { CoreBaseDomainServiceConfig } from '../../core/domain';
12
+ import type { ServiceOptions } from '../../api';
13
+ /**
14
+ * Requirement specification for a single feature flag
15
+ */
16
+ export interface ServiceFlagRequirement {
17
+ /** The feature flag key */
18
+ key: string;
19
+ /** Expected value (if undefined, just checks if enabled) */
20
+ expectedValue?: FeatureFlagValue;
21
+ /** Whether this flag is required for the service to operate */
22
+ required: boolean;
23
+ /** Default value to use if flag is not found */
24
+ default?: FeatureFlagValue;
25
+ /** Human-readable description of what this flag controls */
26
+ description?: string;
27
+ }
28
+ /**
29
+ * Result of validating flag requirements
30
+ */
31
+ export interface FlagRequirementValidationResult {
32
+ /** Whether all required flags are satisfied */
33
+ isValid: boolean;
34
+ /** Array of validation errors */
35
+ errors: FlagRequirementError[];
36
+ /** Array of validation warnings */
37
+ warnings: FlagRequirementWarning[];
38
+ /** Flags that were not found but had defaults applied */
39
+ defaultsApplied: string[];
40
+ }
41
+ /**
42
+ * Error when a required flag is missing or has wrong value
43
+ */
44
+ export interface FlagRequirementError {
45
+ /** The flag key that failed validation */
46
+ key: string;
47
+ /** The expected value (if any) */
48
+ expectedValue?: FeatureFlagValue;
49
+ /** The actual value found */
50
+ actualValue?: FeatureFlagValue;
51
+ /** Error message */
52
+ message: string;
53
+ /** Whether the flag was not found at all */
54
+ notFound: boolean;
55
+ }
56
+ /**
57
+ * Warning for non-required flag issues
58
+ */
59
+ export interface FlagRequirementWarning {
60
+ /** The flag key */
61
+ key: string;
62
+ /** Warning message */
63
+ message: string;
64
+ /** The default value that was applied */
65
+ defaultApplied?: FeatureFlagValue;
66
+ }
67
+ /**
68
+ * Error thrown when flag requirements are not met
69
+ */
70
+ export interface ServiceFlagRequirementsErrorDetails {
71
+ /** Service name that has unmet requirements */
72
+ serviceName: string;
73
+ /** Array of requirement errors */
74
+ errors: FlagRequirementError[];
75
+ }
76
+ /**
77
+ * Error thrown when a feature is disabled
78
+ */
79
+ export interface FeatureDisabledErrorDetails {
80
+ /** The flag key that is disabled */
81
+ flagKey: string;
82
+ /** Optional message */
83
+ message?: string;
84
+ }
85
+ /**
86
+ * Error thrown when a flag value doesn't match expected
87
+ */
88
+ export interface FeatureFlagMismatchErrorDetails {
89
+ /** The flag key */
90
+ flagKey: string;
91
+ /** The expected value */
92
+ expectedValue: FeatureFlagValue;
93
+ /** The actual value */
94
+ actualValue: FeatureFlagValue | undefined;
95
+ }
96
+ /**
97
+ * Interface for services that depend on feature flags
98
+ */
99
+ export interface FlagDependentServiceInterface {
100
+ /**
101
+ * Validate that all flag requirements are met
102
+ * Called during service initialization
103
+ */
104
+ validateFlagRequirements(): Promise<FlagRequirementValidationResult>;
105
+ /**
106
+ * Get the flag requirements for this service
107
+ */
108
+ getFlagRequirements(): ServiceFlagRequirement[];
109
+ }
110
+ /**
111
+ * Configuration for flag-dependent service base class
112
+ */
113
+ export interface FlagDependentServiceConfig {
114
+ /** Service name (for error messages) */
115
+ serviceName: string;
116
+ /** Flag requirements */
117
+ requirements: ServiceFlagRequirement[];
118
+ /** Whether to throw on validation failure */
119
+ throwOnValidationFailure?: boolean;
120
+ /** Whether to log warnings */
121
+ logWarnings?: boolean;
122
+ }
123
+ /**
124
+ * Utility type to extract flag keys from requirements array
125
+ */
126
+ export type ExtractFlagKeys<T extends readonly ServiceFlagRequirement[]> = T[number]['key'];
127
+ /**
128
+ * Utility type to create a typed flag map from requirements
129
+ */
130
+ export type FlagMapFromRequirements<T extends readonly ServiceFlagRequirement[]> = {
131
+ [K in T[number]['key']]: FeatureFlagValue;
132
+ };
133
+ /**
134
+ * Feature flag event types (backend domain service)
135
+ */
136
+ export type FeatureFlagDomainEventType = 'featureFlag:backend:evaluating' | 'featureFlag:backend:evaluated' | 'featureFlag:backend:evaluate:error' | 'featureFlag:backend:creating' | 'featureFlag:backend:created' | 'featureFlag:backend:create:error' | 'featureFlag:backend:updating' | 'featureFlag:backend:updated' | 'featureFlag:backend:update:error' | 'featureFlag:backend:deleting' | 'featureFlag:backend:deleted' | 'featureFlag:backend:delete:error' | 'featureFlag:backend:override:setting' | 'featureFlag:backend:override:set' | 'featureFlag:backend:override:removing' | 'featureFlag:backend:override:removed' | 'featureFlag:backend:provider:initialized' | 'featureFlag:backend:provider:refreshed' | 'featureFlag:backend:provider:disposed';
137
+ /**
138
+ * Backend Feature Flag Domain Service configuration
139
+ */
140
+ export interface FeatureFlagDomainServiceConfig extends CoreBaseDomainServiceConfig {
141
+ /** Default context for evaluations */
142
+ defaultContext?: FeatureFlagContext;
143
+ /** Feature flag provider (database, redis, memory, etc.) */
144
+ provider: FeatureFlagProvider<string>;
145
+ }
146
+ /**
147
+ * API client type for service options
148
+ */
149
+ type ApiClientType = NonNullable<ServiceOptions['apiClient']>;
150
+ /**
151
+ * API Feature Flag Provider Configuration (extends base config)
152
+ */
153
+ export interface ApiFeatureFlagConfig<TKey extends string> extends FeatureFlagConfig<TKey> {
154
+ /** API client instance to use for requests */
155
+ apiClient: ApiClientType;
156
+ /** Optional context for evaluations */
157
+ context?: FeatureFlagContext;
158
+ }
159
+ /**
160
+ * Options for creating feature flag config
161
+ *
162
+ * Note: Database connection is handled by DbService (via Core.initialize()),
163
+ * so no connection string is needed here. The database provider will use
164
+ * the already-configured DbService.
165
+ *
166
+ * Environment is read from Core.env.NODE_ENV - no need to pass it.
167
+ */
168
+ export interface FeatureFlagConfigOptions {
169
+ /** Provider type - 'database' uses DbService which must be initialized via Core.initialize() */
170
+ provider?: 'memory' | 'database' | 'redis' | 'api' | 'file';
171
+ /** Enable caching */
172
+ cacheEnabled?: boolean;
173
+ /** Cache TTL in seconds */
174
+ cacheTtl?: number;
175
+ /** Refresh interval in seconds */
176
+ refreshInterval?: number;
177
+ /** Enable logging (defaults to true in development based on Core.env.NODE_ENV) */
178
+ loggingEnabled?: boolean;
179
+ /** Fallback to defaults when flag not found */
180
+ fallbackToDefaults?: boolean;
181
+ /** Table name for database provider (defaults to 'feature_flags') */
182
+ tableName?: string;
183
+ }
184
+ export {};