@plyaz/types 1.18.1 → 1.18.3

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 (54) hide show
  1. package/dist/api/endpoints/featureFlags/endpoints.d.ts +83 -0
  2. package/dist/api/endpoints/featureFlags/index.d.ts +8 -0
  3. package/dist/api/endpoints/featureFlags/types.d.ts +153 -0
  4. package/dist/api/endpoints/index.d.ts +1 -0
  5. package/dist/api/endpoints/types.d.ts +2 -1
  6. package/dist/api/index.cjs +52 -0
  7. package/dist/api/index.cjs.map +1 -1
  8. package/dist/api/index.d.ts +1 -0
  9. package/dist/api/index.js +52 -0
  10. package/dist/api/index.js.map +1 -1
  11. package/dist/core/events/index.d.ts +4 -0
  12. package/dist/core/events/payloads.d.ts +168 -0
  13. package/dist/core/featureFlag/enums.d.ts +11 -6
  14. package/dist/core/featureFlag/types.d.ts +146 -1
  15. package/dist/core/index.d.ts +3 -0
  16. package/dist/core/modules.d.ts +408 -0
  17. package/dist/db/audit.types.d.ts +22 -0
  18. package/dist/db/config.types.d.ts +21 -1
  19. package/dist/db/database.types.d.ts +2 -0
  20. package/dist/db/databaseAdapter.d.ts +13 -3
  21. package/dist/db/databaseService.d.ts +21 -48
  22. package/dist/db/dbEnums.d.ts +33 -5
  23. package/dist/db/extensions.types.d.ts +35 -0
  24. package/dist/db/features-config.types.d.ts +28 -2
  25. package/dist/db/health.types.d.ts +16 -0
  26. package/dist/db/index.cjs +20 -3
  27. package/dist/db/index.cjs.map +1 -1
  28. package/dist/db/index.d.ts +5 -0
  29. package/dist/db/index.js +20 -4
  30. package/dist/db/index.js.map +1 -1
  31. package/dist/db/migrations.types.d.ts +60 -0
  32. package/dist/db/seeds.types.d.ts +49 -0
  33. package/dist/db/tenant.types.d.ts +14 -0
  34. package/dist/errors/codes.d.ts +8 -0
  35. package/dist/errors/enums.d.ts +3 -0
  36. package/dist/errors/index.cjs +55 -0
  37. package/dist/errors/index.cjs.map +1 -1
  38. package/dist/errors/index.js +55 -0
  39. package/dist/errors/index.js.map +1 -1
  40. package/dist/examples/index.cjs +76 -0
  41. package/dist/examples/index.cjs.map +1 -0
  42. package/dist/examples/index.d.ts +17 -0
  43. package/dist/examples/index.js +68 -0
  44. package/dist/examples/index.js.map +1 -0
  45. package/dist/examples/schemas.d.ts +119 -0
  46. package/dist/examples/types.d.ts +103 -0
  47. package/dist/features/feature-flag/types.d.ts +62 -32
  48. package/dist/index.cjs +107 -14
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.ts +4 -0
  51. package/dist/index.js +103 -14
  52. package/dist/index.js.map +1 -1
  53. package/dist/payments/provider/core/types.d.ts +2 -0
  54. package/package.json +6 -1
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Core Events Types
3
+ */
4
+ export type { CoreCrudOperation, CoreValidationStartedPayload, CoreValidationSuccessPayload, CoreValidationFailedPayload, CoreSanitizationStartedPayload, CoreSanitizationSuccessPayload, CoreSanitizationFailedPayload, CoreEntityCreatedPayload, CoreEntityUpdatedPayload, CoreEntityPatchedPayload, CoreEntityDeletedPayload, CoreEntityCreatingPayload, CoreEntityUpdatingPayload, CoreEntityPatchingPayload, CoreEntityDeletingPayload, CoreEntityErrorPayload, CoreEntityCompletePayload, CoreBulkCreatedPayload, CoreBulkDeletedPayload, } from './payloads';
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Core Event Payloads for CoreEventManager
3
+ *
4
+ * Base payload types that domains can extend for type-safe events.
5
+ * All types prefixed with `Core` to avoid conflicts with domain-specific types.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Extending for a specific domain
10
+ * interface CampaignCreatedPayload extends CoreEntityCreatedPayload<Campaign, CampaignStoreItem> {
11
+ * notifyFollowers?: boolean;
12
+ * }
13
+ * ```
14
+ */
15
+ /**
16
+ * CRUD operation types
17
+ */
18
+ export type CoreCrudOperation = 'create' | 'update' | 'patch' | 'delete' | 'query';
19
+ /**
20
+ * Payload for validation:started events
21
+ */
22
+ export interface CoreValidationStartedPayload {
23
+ operation: CoreCrudOperation;
24
+ entityId?: string;
25
+ data: unknown;
26
+ }
27
+ /**
28
+ * Payload for validation:success events
29
+ */
30
+ export interface CoreValidationSuccessPayload<TValidated = unknown> {
31
+ operation: CoreCrudOperation;
32
+ entityId?: string;
33
+ validatedData: TValidated;
34
+ }
35
+ /**
36
+ * Payload for validation:failed events
37
+ */
38
+ export interface CoreValidationFailedPayload {
39
+ operation: CoreCrudOperation;
40
+ entityId?: string;
41
+ error: unknown;
42
+ }
43
+ /**
44
+ * Payload for sanitization:started events
45
+ */
46
+ export interface CoreSanitizationStartedPayload {
47
+ operation: CoreCrudOperation;
48
+ entityId?: string;
49
+ data: unknown;
50
+ }
51
+ /**
52
+ * Payload for sanitization:success events
53
+ */
54
+ export interface CoreSanitizationSuccessPayload<TSanitized = unknown> {
55
+ operation: CoreCrudOperation;
56
+ entityId?: string;
57
+ sanitizedData: TSanitized;
58
+ changedFields?: string[];
59
+ }
60
+ /**
61
+ * Payload for sanitization:failed events
62
+ */
63
+ export interface CoreSanitizationFailedPayload {
64
+ operation: CoreCrudOperation;
65
+ entityId?: string;
66
+ error: unknown;
67
+ }
68
+ /**
69
+ * Payload for entity:created events
70
+ *
71
+ * @typeParam TEntity - Domain entity type
72
+ * @typeParam TStoreState - Serializable store state type
73
+ */
74
+ export interface CoreEntityCreatedPayload<TEntity, TStoreState = TEntity> {
75
+ entity: TEntity;
76
+ storeState: TStoreState;
77
+ }
78
+ /**
79
+ * Payload for entity:updated events
80
+ *
81
+ * @typeParam TEntity - Domain entity type
82
+ * @typeParam TStoreState - Serializable store state type
83
+ */
84
+ export interface CoreEntityUpdatedPayload<TEntity, TStoreState = TEntity> {
85
+ entity: TEntity;
86
+ storeState: TStoreState;
87
+ previousState?: TStoreState;
88
+ }
89
+ /**
90
+ * Payload for entity:patched events (partial update)
91
+ *
92
+ * @typeParam TEntity - Domain entity type
93
+ * @typeParam TStoreState - Serializable store state type
94
+ */
95
+ export interface CoreEntityPatchedPayload<TEntity, TStoreState = TEntity> {
96
+ entity: TEntity;
97
+ storeState: TStoreState;
98
+ changedFields?: (keyof TEntity)[];
99
+ }
100
+ /**
101
+ * Payload for entity:deleted events
102
+ */
103
+ export interface CoreEntityDeletedPayload {
104
+ id: string;
105
+ soft: boolean;
106
+ }
107
+ /**
108
+ * Payload for entity:creating events (before API call)
109
+ */
110
+ export interface CoreEntityCreatingPayload<TRequest> {
111
+ request: TRequest;
112
+ }
113
+ /**
114
+ * Payload for entity:updating events (before API call)
115
+ */
116
+ export interface CoreEntityUpdatingPayload<TRequest> {
117
+ id: string;
118
+ request: TRequest;
119
+ }
120
+ /**
121
+ * Payload for entity:patching events (before API call)
122
+ */
123
+ export interface CoreEntityPatchingPayload<TRequest> {
124
+ id: string;
125
+ request: TRequest;
126
+ }
127
+ /**
128
+ * Payload for entity:deleting events (before API call)
129
+ */
130
+ export interface CoreEntityDeletingPayload {
131
+ id: string;
132
+ options?: {
133
+ soft: boolean;
134
+ };
135
+ }
136
+ /**
137
+ * Payload for entity:*:error events
138
+ */
139
+ export interface CoreEntityErrorPayload {
140
+ error: unknown;
141
+ entityId?: string;
142
+ }
143
+ /**
144
+ * Payload for entity:*:complete events (regardless of success/failure)
145
+ */
146
+ export interface CoreEntityCompletePayload {
147
+ success?: boolean;
148
+ entityId?: string;
149
+ }
150
+ /**
151
+ * Payload for bulk entity creation
152
+ *
153
+ * @typeParam TEntity - Domain entity type
154
+ * @typeParam TStoreState - Serializable store state type
155
+ */
156
+ export interface CoreBulkCreatedPayload<TEntity, TStoreState = TEntity> {
157
+ entities: TEntity[];
158
+ storeStates: TStoreState[];
159
+ total: number;
160
+ }
161
+ /**
162
+ * Payload for bulk entity deletion
163
+ */
164
+ export interface CoreBulkDeletedPayload {
165
+ ids: string[];
166
+ soft: boolean;
167
+ total: number;
168
+ }
@@ -6,9 +6,9 @@ export declare enum SORT_DIRECTION {
6
6
  Desc = "desc"
7
7
  }
8
8
  /**
9
- * Database table names enumeration
9
+ * Feature flag database table names enumeration
10
10
  */
11
- export declare enum DATABASE_TABLE {
11
+ export declare enum FEATURE_FLAG_TABLE {
12
12
  FeatureFlags = "feature_flags",
13
13
  FeatureFlagRules = "feature_flag_rules",
14
14
  FeatureFlagEvaluations = "feature_flag_evaluations",
@@ -19,7 +19,9 @@ export declare enum DATABASE_TABLE {
19
19
  */
20
20
  export declare enum FEATURE_FLAG_FIELD {
21
21
  Key = "key",
22
+ Name = "name",
22
23
  Value = "value",
24
+ Type = "type",
23
25
  IsEnabled = "is_enabled",
24
26
  Environments = "environments",
25
27
  Description = "description",
@@ -78,12 +80,15 @@ export declare enum SYSTEM_USERS {
78
80
  }
79
81
  /**
80
82
  * Evaluation Reasons
83
+ * Must match database enum: evaluation_reason
84
+ * Used when logging feature flag evaluations to audit table
81
85
  */
82
86
  export declare enum EVALUATION_REASONS {
83
- EVALUATION = "evaluation",
84
- DefaultValue = "default_value",
85
- RuleMatch = "rule_match",
86
- OVERRIDE = "override"
87
+ Default = "default",// Default flag value used
88
+ RuleMatch = "rule_match",// Matched a targeting rule
89
+ Rollout = "rollout",// Matched rollout percentage
90
+ Override = "override",// User-specific override applied
91
+ Disabled = "disabled"
87
92
  }
88
93
  /**
89
94
  * Feature Flag Types
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import type { FEATURES } from '@plyaz/config';
9
9
  import type { FeatureFlagCondition, FeatureFlagConfig, FeatureFlagValue } from '../../features';
10
+ import type { ApiClientWithEvents } from '../../api';
10
11
  /**
11
12
  * Raw database row interface for feature flags table
12
13
  */
@@ -55,8 +56,10 @@ export interface DatabaseEvaluationRow {
55
56
  flag_key: string;
56
57
  user_id?: string;
57
58
  context?: Record<string, string | number | boolean>;
58
- result: FeatureFlagValue;
59
+ value: FeatureFlagValue;
60
+ is_enabled: boolean;
59
61
  reason: string;
62
+ matched_rule_id?: string;
60
63
  evaluated_at: string;
61
64
  }
62
65
  /**
@@ -110,3 +113,145 @@ export interface FeatureFlagEnvironmentConfig extends Omit<FeatureFlagConfig<Fea
110
113
  */
111
114
  export type FeatureFlagKey = keyof typeof FEATURES;
112
115
  export type FeatureFlags = typeof FEATURES extends Record<FeatureFlagKey, FeatureFlagValue> ? typeof FEATURES : never;
116
+ /**
117
+ * Feature flag module configuration for NestJS/Core integration
118
+ */
119
+ export interface CoreFeatureFlagModuleConfig {
120
+ /** Provider type for flag storage */
121
+ provider?: 'memory' | 'database' | 'redis' | 'api' | 'file';
122
+ /** How often to refresh flag data in seconds (0 = no auto-refresh) */
123
+ refreshInterval?: number;
124
+ /** Enable debug logging */
125
+ loggingEnabled?: boolean;
126
+ /** Database configuration (optional - uses defaults if provider is 'database') */
127
+ db?: {
128
+ /** Table name for feature flags (default: 'feature_flags') */
129
+ tableName?: string;
130
+ /** Table name for feature flag rules (default: 'feature_flag_rules') */
131
+ rulesTableName?: string;
132
+ /** Table name for feature flag evaluations (default: 'feature_flag_evaluations') */
133
+ evaluationsTableName?: string;
134
+ /** Table name for feature flag overrides (default: 'feature_flag_overrides') */
135
+ overridesTableName?: string;
136
+ /** Schema for evaluations table (default: 'public', use 'audit' for partitioned tables) */
137
+ evaluationsSchema?: string;
138
+ };
139
+ /** Redis configuration (required if provider is 'redis') */
140
+ redis?: {
141
+ /** Redis connection URL (e.g., 'redis://localhost:6379') */
142
+ url: string;
143
+ /** Key prefix for feature flags (default: 'feature_flags:') */
144
+ keyPrefix?: string;
145
+ };
146
+ /**
147
+ * API configuration (for provider: 'api')
148
+ * Uses @plyaz/api package with predefined endpoints (e.g., api.fetchFeatureFlags())
149
+ * Similar to BaseAdapter apiClientConfig pattern
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // Option 1: Provide config (ApiClientService created internally)
154
+ * FeatureFlagModule.forRoot({
155
+ * provider: 'api',
156
+ * api: {
157
+ * clientConfig: {
158
+ * baseURL: 'https://flags.example.com',
159
+ * timeout: 5000,
160
+ * headers: { static: { 'X-API-Key': '...' } }
161
+ * }
162
+ * }
163
+ * })
164
+ *
165
+ * // Option 2: Inject existing ApiClientService (for shared client)
166
+ * FeatureFlagModule.forRoot({
167
+ * provider: 'api',
168
+ * api: { client: existingApiClientService }
169
+ * })
170
+ * ```
171
+ */
172
+ api?: {
173
+ /**
174
+ * API client configuration (follows ApiConfig from @plyaz/types/api)
175
+ * Used to create a dedicated ApiClientService for feature flags
176
+ */
177
+ clientConfig?: {
178
+ /** Base URL for the feature flags API service */
179
+ baseURL: string;
180
+ /** Request timeout in milliseconds */
181
+ timeout?: number;
182
+ /** Headers configuration */
183
+ headers?: {
184
+ /** Static headers included in all requests */
185
+ static?: Record<string, string>;
186
+ /** Dynamic headers generated per request */
187
+ dynamic?: Record<string, () => string | Promise<string>>;
188
+ };
189
+ /** Retry configuration */
190
+ retry?: {
191
+ maxRetries?: number;
192
+ retryDelay?: number;
193
+ };
194
+ };
195
+ /**
196
+ * Inject an existing ApiClientService instance
197
+ * Useful when sharing a client across services or for testing
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * import { ApiClientService } from '@plyaz/core';
202
+ *
203
+ * // Initialize the service first
204
+ * await ApiClientService.init({ env: 'production' }, { baseURL: '...' });
205
+ *
206
+ * // Then inject it
207
+ * FeatureFlagModule.forRoot({
208
+ * provider: 'api',
209
+ * api: { client: ApiClientService.getClient() }
210
+ * })
211
+ * ```
212
+ */
213
+ client?: ApiClientWithEvents<unknown, unknown>;
214
+ };
215
+ /** File configuration (optional - uses defaults if provider is 'file') */
216
+ file?: {
217
+ /** Path to the feature flags file (default: './feature-flags.json') */
218
+ path?: string;
219
+ /** File format: 'json' or 'yaml' (default: 'json') */
220
+ format?: 'json' | 'yaml';
221
+ /** Watch file for changes (default: false) */
222
+ watch?: boolean;
223
+ };
224
+ /** Cache configuration */
225
+ cache?: {
226
+ /** Enable caching of flag evaluations (default: true) */
227
+ enabled?: boolean;
228
+ /** Cache time-to-live in seconds (default: 300) */
229
+ ttl?: number;
230
+ };
231
+ }
232
+ /**
233
+ * Configuration for database table names.
234
+ * Allows customization of table names for different environments (dev, test, prod).
235
+ */
236
+ export interface FeatureFlagTableConfig {
237
+ /** Table name for feature flags (default: 'feature_flags') */
238
+ flagsTable: string;
239
+ /** Table name for feature flag rules (default: 'feature_flag_rules') */
240
+ rulesTable: string;
241
+ /** Table name for feature flag evaluations (default: 'feature_flag_evaluations') */
242
+ evaluationsTable: string;
243
+ /** Table name for feature flag overrides (default: 'feature_flag_overrides') */
244
+ overridesTable: string;
245
+ /** Schema for evaluations table (default: 'public') */
246
+ evaluationsSchema: string;
247
+ }
248
+ /**
249
+ * Feature flag request type for middleware
250
+ * Extended request object with feature flag properties
251
+ */
252
+ export interface CoreFeatureFlagRequest {
253
+ featureFlags?: Record<string, boolean>;
254
+ query?: Record<string, unknown> | URLSearchParams;
255
+ headers?: Record<string, string | string[] | undefined>;
256
+ url?: string;
257
+ }
@@ -6,9 +6,12 @@
6
6
  */
7
7
  export type { ApiEnvironmentConfig, ApiProviderProps } from './services';
8
8
  export type { CoreIdempotencyStoreType, CoreInMemoryIdempotencyAdapterConfig, CoreRedisIdempotencyAdapterConfig, CoreIdempotencyStoreOptions, CoreIdempotencyStoreConfig, } from './idempotency';
9
+ export type { CoreServices, CoreRouteContext, CoreRouteHandler, CoreRouteDefinition, CoreModuleConfigSchema, CoreServiceFactory, CoreModuleLifecycle, CoreModuleDefinition, CoreRegisteredModule, CoreConfiguredModule, CoreModuleFactory, CoreFrameworkType, CoreServerConfig, CoreFrameworkAdapter, CoreAdapterFactory, CoreRuntimeEnvironment, CoreRuntimeContext, CoreNextJsHandlerContext, CoreNextJsHandlerResult, CoreNextJsHandler, CoreNextJsHandlerOptions, CoreEnvVars, CoreAppEnvironment, CoreApiInitOptions, CoreInitOptions, CoreServicesResult, CoreNestJsModuleOptions, CoreNestJsModuleAsyncOptions, } from './modules';
10
+ export { BACKEND_RUNTIMES, FRONTEND_RUNTIMES, UNIVERSAL_RUNTIMES } from './modules';
9
11
  export * from './tables/enum';
10
12
  export type * from './auth/types';
11
13
  export type * from './featureFlag/types';
12
14
  export * from './featureFlag/enums';
13
15
  export * from './featureFlag/constants';
16
+ export type * from './events';
14
17
  export type * from './types';