@plyaz/types 1.19.4 → 1.20.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.
- package/dist/api/client/types.d.ts +59 -0
- package/dist/api/index.cjs +29 -0
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.js +29 -0
- package/dist/api/index.js.map +1 -1
- package/dist/core/auth/types.d.ts +1 -1
- package/dist/core/domain/index.d.ts +5 -0
- package/dist/core/domain/types.d.ts +123 -0
- package/dist/core/events/enums.d.ts +25 -1
- package/dist/core/events/index.d.ts +3 -3
- package/dist/core/events/payloads.d.ts +80 -1
- package/dist/core/featureFlag/types.d.ts +16 -16
- package/dist/core/frontend/featureFlags.d.ts +106 -0
- package/dist/core/frontend/index.d.ts +6 -0
- package/dist/core/frontend/types.d.ts +318 -0
- package/dist/core/index.d.ts +6 -2
- package/dist/core/init/index.d.ts +5 -0
- package/dist/core/init/types.d.ts +347 -0
- package/dist/core/modules.d.ts +19 -3
- package/dist/core/services/index.d.ts +5 -0
- package/dist/core/{services.d.ts → services/types.d.ts} +74 -6
- package/dist/errors/codes.d.ts +3 -0
- package/dist/errors/index.cjs +29 -0
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +29 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/middleware.d.ts +105 -0
- package/dist/errors/store.d.ts +140 -0
- package/dist/examples/index.d.ts +1 -1
- package/dist/examples/types.d.ts +64 -0
- package/dist/features/feature-flag/dto.types.d.ts +67 -0
- package/dist/features/feature-flag/index.d.ts +3 -0
- package/dist/features/feature-flag/service.types.d.ts +184 -0
- package/dist/features/feature-flag/store.types.d.ts +166 -0
- package/dist/features/feature-flag/types.d.ts +16 -4
- package/dist/globals.d.ts +23 -0
- package/dist/index.cjs +49 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/dist/store/index.cjs +13 -0
- package/dist/store/index.cjs.map +1 -1
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +11 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/keys.d.ts +23 -0
- package/dist/store/types.d.ts +62 -71
- package/dist/testing/features/feature-flags/types.d.ts +3 -3
- package/package.json +6 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature Flag Store Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the feature flag store slice.
|
|
5
|
+
* Used by @plyaz/store for state management.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Feature flag store type definitions
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
import type { FeatureFlagValue, FeatureFlagRule } from './types';
|
|
11
|
+
import type { PackageErrorLike } from '../../errors';
|
|
12
|
+
/**
|
|
13
|
+
* Metadata associated with a feature flag in the store
|
|
14
|
+
*/
|
|
15
|
+
export interface FeatureFlagStoreMetadata {
|
|
16
|
+
/** Associated rules for the flag */
|
|
17
|
+
rules?: FeatureFlagRule<string>[];
|
|
18
|
+
/** Last time this flag was updated */
|
|
19
|
+
updatedAt?: Date;
|
|
20
|
+
/** Source of the flag value */
|
|
21
|
+
source?: 'api' | 'database' | 'redis' | 'memory' | 'file' | 'default';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Polling configuration for feature flags
|
|
25
|
+
*/
|
|
26
|
+
export interface FeatureFlagPollingConfig {
|
|
27
|
+
/** Whether polling is enabled */
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
/** Polling interval in milliseconds */
|
|
30
|
+
interval: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Feature flag store state
|
|
34
|
+
*/
|
|
35
|
+
export interface FeatureFlagStoreState {
|
|
36
|
+
/** Map of flag keys to their values */
|
|
37
|
+
flags: Record<string, FeatureFlagValue>;
|
|
38
|
+
/** Default values to use when flag is not found */
|
|
39
|
+
defaults: Record<string, FeatureFlagValue>;
|
|
40
|
+
/** Metadata for each flag */
|
|
41
|
+
metadata: Record<string, FeatureFlagStoreMetadata>;
|
|
42
|
+
/** Timestamp of last fetch */
|
|
43
|
+
lastFetched: number | null;
|
|
44
|
+
/** Whether flags are currently being loaded */
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
/** Whether the store has been initialized */
|
|
47
|
+
isInitialized: boolean;
|
|
48
|
+
/** Current error state */
|
|
49
|
+
error: PackageErrorLike | null;
|
|
50
|
+
/** Polling configuration */
|
|
51
|
+
pollingConfig: FeatureFlagPollingConfig | null;
|
|
52
|
+
/** Active polling interval ID (for cleanup) */
|
|
53
|
+
pollingIntervalId: ReturnType<typeof globalThis.setInterval> | null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Feature flag store actions
|
|
57
|
+
*/
|
|
58
|
+
export interface FeatureFlagStoreActions {
|
|
59
|
+
/**
|
|
60
|
+
* Initialize the store with optional configuration
|
|
61
|
+
*/
|
|
62
|
+
initialize(config?: FeatureFlagStoreInitConfig): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Fetch all flags from the configured source
|
|
65
|
+
*/
|
|
66
|
+
fetchAll(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Refresh flags (re-fetch from source)
|
|
69
|
+
*/
|
|
70
|
+
refresh(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Set flags in the store
|
|
73
|
+
*/
|
|
74
|
+
setFlags(flags: Record<string, FeatureFlagValue>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Update flags (merge with existing)
|
|
77
|
+
*/
|
|
78
|
+
updateFlags(flags: Record<string, FeatureFlagValue>): void;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a flag is enabled
|
|
81
|
+
* Returns synchronously from store (with warning if flag not found)
|
|
82
|
+
*/
|
|
83
|
+
isEnabled(key: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Get the value of a flag
|
|
86
|
+
*/
|
|
87
|
+
getValue<T = FeatureFlagValue>(key: string): T | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Get value with a default fallback
|
|
90
|
+
*/
|
|
91
|
+
getValueOrDefault<T = FeatureFlagValue>(key: string, fallback: T): T;
|
|
92
|
+
/**
|
|
93
|
+
* Set a single default value
|
|
94
|
+
*/
|
|
95
|
+
setDefault(key: string, value: FeatureFlagValue): void;
|
|
96
|
+
/**
|
|
97
|
+
* Set multiple default values
|
|
98
|
+
*/
|
|
99
|
+
setDefaults(defaults: Record<string, FeatureFlagValue>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Configure polling
|
|
102
|
+
*/
|
|
103
|
+
setPollingConfig(config: FeatureFlagPollingConfig | null): void;
|
|
104
|
+
/**
|
|
105
|
+
* Start polling for flag updates
|
|
106
|
+
*/
|
|
107
|
+
startPolling(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Stop polling
|
|
110
|
+
*/
|
|
111
|
+
stopPolling(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Set loading state
|
|
114
|
+
*/
|
|
115
|
+
setLoading(isLoading: boolean): void;
|
|
116
|
+
/**
|
|
117
|
+
* Set error state
|
|
118
|
+
*/
|
|
119
|
+
setError(error: PackageErrorLike | null): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear all flags and reset store
|
|
122
|
+
*/
|
|
123
|
+
reset(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Dispose of the store (cleanup)
|
|
126
|
+
*/
|
|
127
|
+
dispose(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Combined store slice type
|
|
131
|
+
*/
|
|
132
|
+
export type FeatureFlagStoreSlice = FeatureFlagStoreState & FeatureFlagStoreActions;
|
|
133
|
+
/**
|
|
134
|
+
* Configuration for store initialization
|
|
135
|
+
*/
|
|
136
|
+
export interface FeatureFlagStoreInitConfig {
|
|
137
|
+
/** Default flag values */
|
|
138
|
+
defaults?: Record<string, FeatureFlagValue>;
|
|
139
|
+
/** Polling configuration */
|
|
140
|
+
polling?: FeatureFlagPollingConfig;
|
|
141
|
+
/** Fetch function to get flags from source */
|
|
142
|
+
fetchFn?: () => Promise<Record<string, FeatureFlagValue>>;
|
|
143
|
+
/** Callback when flags change */
|
|
144
|
+
onFlagChange?: (key: string, prevValue: FeatureFlagValue | undefined, newValue: FeatureFlagValue) => void;
|
|
145
|
+
/** Callback when an error occurs */
|
|
146
|
+
onError?: (error: PackageErrorLike) => void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Selector functions for the feature flag store
|
|
150
|
+
*/
|
|
151
|
+
export interface FeatureFlagStoreSelectors {
|
|
152
|
+
/** Select all flags */
|
|
153
|
+
selectFlags: (state: FeatureFlagStoreState) => Record<string, FeatureFlagValue>;
|
|
154
|
+
/** Select a specific flag value */
|
|
155
|
+
selectFlag: (state: FeatureFlagStoreState, key: string) => FeatureFlagValue | undefined;
|
|
156
|
+
/** Select whether a flag is enabled */
|
|
157
|
+
selectIsEnabled: (state: FeatureFlagStoreState, key: string) => boolean;
|
|
158
|
+
/** Select loading state */
|
|
159
|
+
selectIsLoading: (state: FeatureFlagStoreState) => boolean;
|
|
160
|
+
/** Select initialization state */
|
|
161
|
+
selectIsInitialized: (state: FeatureFlagStoreState) => boolean;
|
|
162
|
+
/** Select error state */
|
|
163
|
+
selectError: (state: FeatureFlagStoreState) => PackageErrorLike | null;
|
|
164
|
+
/** Select last fetched timestamp */
|
|
165
|
+
selectLastFetched: (state: FeatureFlagStoreState) => number | null;
|
|
166
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { UnknownArray, Arrayable, SetOptional } from 'type-fest';
|
|
10
10
|
import type * as React from 'react';
|
|
11
11
|
import type { Describable, Timestamped, WithMetadata, Loadable, Authored, WithTags, WithEnvironment, Identifiable, Named, WithLogging, WithApiKey, Initializable, Refreshable, WithOperation, Enabled, WithError, KeyValuePair, WithUserId, WithCountry, Versioned, WithPlatform, WithPriority, ValidationResult } from '../../common/types';
|
|
12
|
+
import type { PackageErrorLike } from '../../errors';
|
|
12
13
|
/**
|
|
13
14
|
* Possible values that a feature flag can hold.
|
|
14
15
|
* Supports primitive types and JSON objects for complex configurations.
|
|
@@ -76,12 +77,23 @@ export interface FeatureFlagEvaluation<FeatureFlagKey extends string> extends En
|
|
|
76
77
|
/** Timestamp when this evaluation occurred */
|
|
77
78
|
evaluatedAt: Date;
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Available feature flag provider types.
|
|
82
|
+
* This is the single source of truth for provider types across all packages.
|
|
83
|
+
*
|
|
84
|
+
* - `memory`: In-memory provider using FEATURES constant (ephemeral)
|
|
85
|
+
* - `file`: File-based provider supporting JSON and YAML formats
|
|
86
|
+
* - `redis`: Redis-based provider for distributed caching
|
|
87
|
+
* - `api`: Remote API provider for centralized flag management
|
|
88
|
+
* - `database`: Database provider for persistent flag storage
|
|
89
|
+
*/
|
|
90
|
+
export type FeatureFlagProviderType = 'database' | 'redis' | 'memory' | 'api' | 'file';
|
|
79
91
|
/**
|
|
80
92
|
* Configuration options for the feature flag system.
|
|
81
93
|
*/
|
|
82
94
|
export interface FeatureFlagConfig<FeatureFlagKey extends string> extends SetOptional<WithLogging, 'isLoggingEnabled'>, SetOptional<WithApiKey, 'apiKey'> {
|
|
83
95
|
/** The storage provider to use for flag data */
|
|
84
|
-
provider:
|
|
96
|
+
provider: FeatureFlagProviderType;
|
|
85
97
|
/** Whether to enable caching of flag evaluations */
|
|
86
98
|
isCacheEnabled: boolean;
|
|
87
99
|
/** Cache time-to-live in seconds */
|
|
@@ -167,14 +179,14 @@ export interface FeatureFlagProviderProps<FeatureFlagKey extends string, Feature
|
|
|
167
179
|
/** Callback when provider is ready */
|
|
168
180
|
onReady?: (provider: FeatureFlagProvider<FeatureFlagKey>) => void;
|
|
169
181
|
/** Callback when an error occurs */
|
|
170
|
-
onError?: (error:
|
|
182
|
+
onError?: (error: PackageErrorLike) => void;
|
|
171
183
|
/** Whether to show loading state while initializing */
|
|
172
184
|
isShowLoading?: boolean;
|
|
173
185
|
/** Custom loading component */
|
|
174
186
|
loadingComponent?: React.ComponentType;
|
|
175
187
|
/** Custom error component */
|
|
176
188
|
errorComponent?: React.ComponentType<{
|
|
177
|
-
error:
|
|
189
|
+
error: PackageErrorLike;
|
|
178
190
|
retry: () => void;
|
|
179
191
|
}>;
|
|
180
192
|
}
|
|
@@ -386,7 +398,7 @@ export interface FlagOperationErrorTestInput<FeatureFlagKey extends string> {
|
|
|
386
398
|
/** Flag key involved in the operation */
|
|
387
399
|
flagKey: FeatureFlagKey;
|
|
388
400
|
/** Error that occurred */
|
|
389
|
-
error:
|
|
401
|
+
error: PackageErrorLike;
|
|
390
402
|
/** Expected log message */
|
|
391
403
|
expectedLogMessage: string;
|
|
392
404
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global Type Declarations
|
|
3
|
+
*
|
|
4
|
+
* Extends globalThis with runtime-specific globals for cross-runtime compatibility.
|
|
5
|
+
* These declarations allow TypeScript to recognize runtime-specific globals
|
|
6
|
+
* without errors when checking for their existence.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
// Runtime-specific globals
|
|
11
|
+
// eslint-disable-next-line no-unused-vars
|
|
12
|
+
var Deno: unknown;
|
|
13
|
+
// eslint-disable-next-line no-unused-vars
|
|
14
|
+
var Bun: unknown;
|
|
15
|
+
// eslint-disable-next-line no-unused-vars
|
|
16
|
+
var EdgeRuntime: unknown;
|
|
17
|
+
|
|
18
|
+
// Node.js require with resolve
|
|
19
|
+
// eslint-disable-next-line no-unused-vars
|
|
20
|
+
var require: (((id: string) => unknown) & { resolve?: (id: string) => string }) | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -190,6 +190,7 @@ var CoreEventScope = {
|
|
|
190
190
|
API: "api",
|
|
191
191
|
CACHE: "cache",
|
|
192
192
|
AUTH: "auth",
|
|
193
|
+
DATABASE: "database",
|
|
193
194
|
FEATURE_FLAG: "featureFlag",
|
|
194
195
|
STORE: "store"
|
|
195
196
|
};
|
|
@@ -250,6 +251,15 @@ var AuthEventAction = {
|
|
|
250
251
|
SESSION_EXPIRED: "sessionExpired",
|
|
251
252
|
UNAUTHORIZED: "unauthorized"
|
|
252
253
|
};
|
|
254
|
+
var DatabaseEventAction = {
|
|
255
|
+
CONNECTED: "connected",
|
|
256
|
+
DISCONNECTED: "disconnected",
|
|
257
|
+
QUERY: "query",
|
|
258
|
+
ERROR: "error",
|
|
259
|
+
TRANSACTION_START: "transactionStart",
|
|
260
|
+
TRANSACTION_COMMIT: "transactionCommit",
|
|
261
|
+
TRANSACTION_ROLLBACK: "transactionRollback"
|
|
262
|
+
};
|
|
253
263
|
var FeatureFlagEventAction = {
|
|
254
264
|
CHANGED: "changed",
|
|
255
265
|
EVALUATED: "evaluated",
|
|
@@ -314,6 +324,15 @@ var CORE_EVENTS = {
|
|
|
314
324
|
SESSION_EXPIRED: `${CoreEventScope.AUTH}:${AuthEventAction.SESSION_EXPIRED}`,
|
|
315
325
|
UNAUTHORIZED: `${CoreEventScope.AUTH}:${AuthEventAction.UNAUTHORIZED}`
|
|
316
326
|
},
|
|
327
|
+
DATABASE: {
|
|
328
|
+
CONNECTED: `${CoreEventScope.DATABASE}:${DatabaseEventAction.CONNECTED}`,
|
|
329
|
+
DISCONNECTED: `${CoreEventScope.DATABASE}:${DatabaseEventAction.DISCONNECTED}`,
|
|
330
|
+
QUERY: `${CoreEventScope.DATABASE}:${DatabaseEventAction.QUERY}`,
|
|
331
|
+
ERROR: `${CoreEventScope.DATABASE}:${DatabaseEventAction.ERROR}`,
|
|
332
|
+
TRANSACTION_START: `${CoreEventScope.DATABASE}:${DatabaseEventAction.TRANSACTION_START}`,
|
|
333
|
+
TRANSACTION_COMMIT: `${CoreEventScope.DATABASE}:${DatabaseEventAction.TRANSACTION_COMMIT}`,
|
|
334
|
+
TRANSACTION_ROLLBACK: `${CoreEventScope.DATABASE}:${DatabaseEventAction.TRANSACTION_ROLLBACK}`
|
|
335
|
+
},
|
|
317
336
|
FEATURE_FLAG: {
|
|
318
337
|
CHANGED: `${CoreEventScope.FEATURE_FLAG}:${FeatureFlagEventAction.CHANGED}`,
|
|
319
338
|
EVALUATED: `${CoreEventScope.FEATURE_FLAG}:${FeatureFlagEventAction.EVALUATED}`,
|
|
@@ -1223,6 +1242,10 @@ var ERROR_CODES = {
|
|
|
1223
1242
|
ERROR_SYSTEM_NOT_INITIALIZED: "error.system.not.initialized",
|
|
1224
1243
|
EVENT_FACTORY_NOT_REGISTERED: "error.event.factory.not.registered",
|
|
1225
1244
|
DATABASE_ERROR: "error.database",
|
|
1245
|
+
// Global Error Handler
|
|
1246
|
+
UNCAUGHT_EXCEPTION: "error.uncaught.exception",
|
|
1247
|
+
UNHANDLED_REJECTION: "error.unhandled.rejection",
|
|
1248
|
+
RUNTIME_ERROR: "error.runtime",
|
|
1226
1249
|
// ===== Database Errors =====
|
|
1227
1250
|
// Connection & Configuration
|
|
1228
1251
|
DB_ACCESS_DENIED: "db.access_denied",
|
|
@@ -4363,6 +4386,31 @@ var ERROR_DEFINITIONS = {
|
|
|
4363
4386
|
retryable: false,
|
|
4364
4387
|
userMessage: "errors.database"
|
|
4365
4388
|
},
|
|
4389
|
+
// Global Error Handler
|
|
4390
|
+
[ERROR_CODES.UNCAUGHT_EXCEPTION]: {
|
|
4391
|
+
code: ERROR_CODES.UNCAUGHT_EXCEPTION,
|
|
4392
|
+
status: HTTP_STATUS.INTERNAL_SERVER_ERROR,
|
|
4393
|
+
category: ERROR_CATEGORY.System,
|
|
4394
|
+
severity: ERROR_SEVERITY.Critical,
|
|
4395
|
+
retryable: false,
|
|
4396
|
+
userMessage: "errors.uncaught.exception"
|
|
4397
|
+
},
|
|
4398
|
+
[ERROR_CODES.UNHANDLED_REJECTION]: {
|
|
4399
|
+
code: ERROR_CODES.UNHANDLED_REJECTION,
|
|
4400
|
+
status: HTTP_STATUS.INTERNAL_SERVER_ERROR,
|
|
4401
|
+
category: ERROR_CATEGORY.System,
|
|
4402
|
+
severity: ERROR_SEVERITY.Critical,
|
|
4403
|
+
retryable: false,
|
|
4404
|
+
userMessage: "errors.unhandled.rejection"
|
|
4405
|
+
},
|
|
4406
|
+
[ERROR_CODES.RUNTIME_ERROR]: {
|
|
4407
|
+
code: ERROR_CODES.RUNTIME_ERROR,
|
|
4408
|
+
status: HTTP_STATUS.INTERNAL_SERVER_ERROR,
|
|
4409
|
+
category: ERROR_CATEGORY.System,
|
|
4410
|
+
severity: ERROR_SEVERITY.High,
|
|
4411
|
+
retryable: false,
|
|
4412
|
+
userMessage: "errors.runtime"
|
|
4413
|
+
},
|
|
4366
4414
|
// ===== Database Error Definitions =====
|
|
4367
4415
|
// Connection & Configuration
|
|
4368
4416
|
[ERROR_CODES.DB_ACCESS_DENIED]: {
|
|
@@ -8501,6 +8549,7 @@ exports.DEBUGGER_CONFIG_SOURCES = DEBUGGER_CONFIG_SOURCES;
|
|
|
8501
8549
|
exports.DEBUG_EVENTS = DEBUG_EVENTS;
|
|
8502
8550
|
exports.DEFAULT_THRESHOLDS = DEFAULT_THRESHOLDS;
|
|
8503
8551
|
exports.DOCUMENT_TYPE = DOCUMENT_TYPE;
|
|
8552
|
+
exports.DatabaseEventAction = DatabaseEventAction;
|
|
8504
8553
|
exports.DeviceTokenSchema = DeviceTokenSchema;
|
|
8505
8554
|
exports.ENCRYPTION_DEFAULTS = ENCRYPTION_DEFAULTS;
|
|
8506
8555
|
exports.ENTITY_TYPE = ENTITY_TYPE;
|