@plyaz/types 1.18.1 → 1.18.2

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 (53) 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/package.json +6 -1
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Feature Flag Endpoint Type Definitions
3
+ *
4
+ * Uses fetchff's Endpoint and Req types for type-safe API definitions.
5
+ *
6
+ * Req<TResponse, TBody?, TParams?> generic parameters:
7
+ * - TResponse: The response type returned by the endpoint
8
+ * - TBody: The request body type (use 'never' for GET/DELETE)
9
+ * - TParams: URL path parameters type (use 'never' if no path params)
10
+ *
11
+ * Error Handling:
12
+ * - All endpoints use FeatureFlagErrorResponse for error responses
13
+ * - Errors are accessible via FetchResponse.error (ResponseError from fetchff)
14
+ * - Use FeatureFlagErrorResponse in hooks/consumers for typed error handling
15
+ */
16
+ import type { Endpoint, Req } from 'fetchff';
17
+ import type { EvaluateFlagRequest, EvaluateFlagParams, EvaluateFlagResponse, IsEnabledRequest, IsEnabledParams, IsEnabledResponse, EvaluateAllFlagsRequest, EvaluateAllFlagsResponse, CreateFlagResponse, UpdateFlagParams, UpdateFlagRequest, UpdateFlagResponse, DeleteFlagParams, DeleteFlagResponse, SetOverrideParams, SetOverrideRequest, SetOverrideResponse, RemoveOverrideParams, RemoveOverrideResponse, GetFlagRulesParams, GetFlagRulesResponse, RefreshCacheResponse, FeatureFlagHealthResponse } from './types';
18
+ import type { CreateFlagRequest } from '../../../features';
19
+ /**
20
+ * Feature Flag API endpoint types
21
+ * Complete type definitions for feature flag endpoints
22
+ */
23
+ export interface FeatureFlagEndpointTypes {
24
+ /**
25
+ * POST /feature-flags/:key/evaluate - Evaluate single flag
26
+ * Req<Response, Body, Params>
27
+ */
28
+ evaluateFeatureFlag: Endpoint<Req<EvaluateFlagResponse, EvaluateFlagRequest, EvaluateFlagParams>>;
29
+ /**
30
+ * POST /feature-flags/:key/enabled - Check if flag is enabled
31
+ * Req<Response, Body, Params>
32
+ */
33
+ checkFeatureFlagEnabled: Endpoint<Req<IsEnabledResponse, IsEnabledRequest, IsEnabledParams>>;
34
+ /**
35
+ * POST /feature-flags/evaluate-all - Evaluate all flags
36
+ * Req<Response, Body>
37
+ */
38
+ evaluateAllFeatureFlags: Endpoint<Req<EvaluateAllFlagsResponse, EvaluateAllFlagsRequest>>;
39
+ /**
40
+ * POST /feature-flags - Create flag
41
+ * Req<Response, Body>
42
+ */
43
+ createFeatureFlag: Endpoint<Req<CreateFlagResponse, CreateFlagRequest<string>>>;
44
+ /**
45
+ * PUT /feature-flags/:key - Update flag
46
+ * Req<Response, Body, Params>
47
+ */
48
+ updateFeatureFlag: Endpoint<Req<UpdateFlagResponse, UpdateFlagRequest, UpdateFlagParams>>;
49
+ /**
50
+ * DELETE /feature-flags/:key - Delete flag
51
+ * Req<Response, Body, Params>
52
+ */
53
+ deleteFeatureFlag: Endpoint<Req<DeleteFlagResponse, never, DeleteFlagParams>>;
54
+ /**
55
+ * POST /feature-flags/:key/override - Set override
56
+ * Req<Response, Body, Params>
57
+ */
58
+ setFeatureFlagOverride: Endpoint<Req<SetOverrideResponse, SetOverrideRequest, SetOverrideParams>>;
59
+ /**
60
+ * DELETE /feature-flags/:key/override - Remove override
61
+ * Req<Response, Body, Params>
62
+ */
63
+ removeFeatureFlagOverride: Endpoint<Req<RemoveOverrideResponse, never, RemoveOverrideParams>>;
64
+ /**
65
+ * GET /feature-flags/:key/rules - Get flag rules
66
+ * Req<Response, Body, Params>
67
+ */
68
+ getFeatureFlagRules: Endpoint<Req<GetFlagRulesResponse, never, GetFlagRulesParams>>;
69
+ /**
70
+ * POST /feature-flags/refresh - Refresh cache
71
+ * Req<Response>
72
+ */
73
+ refreshFeatureFlagCache: Endpoint<Req<RefreshCacheResponse>>;
74
+ /**
75
+ * GET /feature-flags/health - Health check
76
+ * Req<Response>
77
+ */
78
+ getFeatureFlagHealth: Endpoint<Req<FeatureFlagHealthResponse>>;
79
+ }
80
+ /**
81
+ * Type guard for feature flag endpoint keys
82
+ */
83
+ export type FeatureFlagEndpointKey = keyof FeatureFlagEndpointTypes;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Feature Flag API Endpoint Types
3
+ *
4
+ * Note: Core types (FeatureFlagValue, FeatureFlagContext, FeatureFlagEvaluation, etc.)
5
+ * are exported from @plyaz/types/features - import them from there
6
+ */
7
+ export type { FeatureFlagEndpointTypes, FeatureFlagEndpointKey } from './endpoints';
8
+ export type { FeatureFlagErrorResponse, EvaluateFlagRequest, EvaluateFlagParams, EvaluateFlagResponse, IsEnabledRequest, IsEnabledParams, IsEnabledResponse, EvaluateAllFlagsRequest, EvaluateAllFlagsResponse, CreateFlagResponse, UpdateFlagParams, UpdateFlagRequest, UpdateFlagResponse, DeleteFlagParams, DeleteFlagResponse, SetOverrideParams, SetOverrideRequest, SetOverrideResponse, RemoveOverrideParams, RemoveOverrideResponse, GetFlagRulesParams, GetFlagRulesResponse, RefreshCacheResponse, FeatureFlagHealthResponse, } from './types';
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Feature Flag API Type Definitions
3
+ *
4
+ * Request/Response types for feature flag API endpoints.
5
+ * Imports core types from @plyaz/types/features.
6
+ *
7
+ * Response types are generic to support custom FeatureFlagKey types.
8
+ * Default to `string` for flexibility when key type is unknown.
9
+ */
10
+ import type { FeatureFlagValue, FeatureFlagContext, FeatureFlagEvaluation, FeatureFlag, FeatureFlagRule } from '../../../features';
11
+ import type { ErrorResponse } from '../../../errors';
12
+ /**
13
+ * Error response type for feature flag API endpoints.
14
+ * Alias allows changing error structure without updating consumers.
15
+ */
16
+ export type FeatureFlagErrorResponse = ErrorResponse;
17
+ /**
18
+ * Request body for evaluating a flag
19
+ */
20
+ export interface EvaluateFlagRequest {
21
+ context?: FeatureFlagContext;
22
+ }
23
+ /**
24
+ * Path parameters
25
+ */
26
+ export interface EvaluateFlagParams {
27
+ key: string;
28
+ }
29
+ /**
30
+ * Response type - returns FeatureFlagEvaluation directly
31
+ * @typeParam TKey - Feature flag key type (defaults to string)
32
+ */
33
+ export type EvaluateFlagResponse<TKey extends string = string> = FeatureFlagEvaluation<TKey>;
34
+ /**
35
+ * Request body
36
+ */
37
+ export interface IsEnabledRequest {
38
+ context?: FeatureFlagContext;
39
+ }
40
+ /**
41
+ * Path parameters
42
+ */
43
+ export interface IsEnabledParams {
44
+ key: string;
45
+ }
46
+ /**
47
+ * Response type
48
+ */
49
+ export interface IsEnabledResponse {
50
+ isEnabled: boolean;
51
+ }
52
+ /**
53
+ * Request body
54
+ */
55
+ export interface EvaluateAllFlagsRequest {
56
+ context?: FeatureFlagContext;
57
+ }
58
+ /**
59
+ * Response type - returns Record<TKey, FeatureFlagEvaluation> directly
60
+ * @typeParam TKey - Feature flag key type (defaults to string)
61
+ */
62
+ export type EvaluateAllFlagsResponse<TKey extends string = string> = Record<TKey, FeatureFlagEvaluation<TKey>>;
63
+ /**
64
+ * Response type - returns FeatureFlag directly
65
+ * @typeParam TKey - Feature flag key type (defaults to string)
66
+ */
67
+ export type CreateFlagResponse<TKey extends string = string> = FeatureFlag<TKey>;
68
+ /**
69
+ * Path parameters
70
+ */
71
+ export interface UpdateFlagParams {
72
+ key: string;
73
+ }
74
+ /**
75
+ * Request body
76
+ */
77
+ export interface UpdateFlagRequest {
78
+ name?: string;
79
+ description?: string;
80
+ defaultValue?: FeatureFlagValue;
81
+ isEnabled?: boolean;
82
+ }
83
+ /**
84
+ * Response type - returns FeatureFlag directly
85
+ * @typeParam TKey - Feature flag key type (defaults to string)
86
+ */
87
+ export type UpdateFlagResponse<TKey extends string = string> = FeatureFlag<TKey>;
88
+ /**
89
+ * Path parameters
90
+ */
91
+ export interface DeleteFlagParams {
92
+ key: string;
93
+ }
94
+ /**
95
+ * Response type
96
+ */
97
+ export interface DeleteFlagResponse {
98
+ isSuccessful: boolean;
99
+ }
100
+ /**
101
+ * Path parameters
102
+ */
103
+ export interface SetOverrideParams {
104
+ key: string;
105
+ }
106
+ /**
107
+ * Request body
108
+ */
109
+ export interface SetOverrideRequest {
110
+ value: FeatureFlagValue;
111
+ }
112
+ /**
113
+ * Response type
114
+ */
115
+ export interface SetOverrideResponse {
116
+ isSuccessful: boolean;
117
+ }
118
+ /**
119
+ * Path parameters
120
+ */
121
+ export interface RemoveOverrideParams {
122
+ key: string;
123
+ }
124
+ /**
125
+ * Response type
126
+ */
127
+ export interface RemoveOverrideResponse {
128
+ isSuccessful: boolean;
129
+ }
130
+ /**
131
+ * Path parameters
132
+ */
133
+ export interface GetFlagRulesParams {
134
+ key: string;
135
+ }
136
+ /**
137
+ * Response type - returns FeatureFlagRule[] directly
138
+ * @typeParam TKey - Feature flag key type (defaults to string)
139
+ */
140
+ export type GetFlagRulesResponse<TKey extends string = string> = FeatureFlagRule<TKey>[];
141
+ /**
142
+ * Response type
143
+ */
144
+ export interface RefreshCacheResponse {
145
+ isSuccessful: boolean;
146
+ }
147
+ /**
148
+ * Response type
149
+ */
150
+ export interface FeatureFlagHealthResponse {
151
+ isInitialized: boolean;
152
+ provider: string;
153
+ }
@@ -1,4 +1,5 @@
1
1
  export type * from './campaigns';
2
+ export type * from './featureFlags';
2
3
  export type * from './health';
3
4
  export type * from './infobip';
4
5
  export type * from './virustotal';
@@ -3,6 +3,7 @@ import type { PollingEndpointTypes } from './health';
3
3
  import type { InfobipEndpointTypes } from './infobip';
4
4
  import type { VirusTotalEndpointTypes } from './virustotal';
5
5
  import type { CloudflareEndpointTypes, CloudFrontEndpointTypes, FastlyEndpointTypes } from './cdn';
6
+ import type { FeatureFlagEndpointTypes } from './featureFlags';
6
7
  /**
7
8
  * Query parameters type - matches fetchff's flexible param handling
8
9
  * Supports objects, URLSearchParams, and arrays of name-value pairs
@@ -11,5 +12,5 @@ export type QueryParams = Record<string, string | number | boolean | string[] |
11
12
  /**
12
13
  * All endpoint types combined
13
14
  */
14
- export interface EndpointTypes extends CampaignEndpointTypes, PollingEndpointTypes, InfobipEndpointTypes, VirusTotalEndpointTypes, CloudflareEndpointTypes, CloudFrontEndpointTypes, FastlyEndpointTypes {
15
+ export interface EndpointTypes extends CampaignEndpointTypes, PollingEndpointTypes, InfobipEndpointTypes, VirusTotalEndpointTypes, CloudflareEndpointTypes, CloudFrontEndpointTypes, FastlyEndpointTypes, FeatureFlagEndpointTypes {
15
16
  }
@@ -579,6 +579,8 @@ var ERROR_CATEGORY = {
579
579
  Plugin: "plugin",
580
580
  /** Quota or storage limit error (e.g., exceeded storage quota). */
581
581
  Quota: "quota",
582
+ /** Database-related error (e.g., query failure, connection error). */
583
+ Database: "database",
582
584
  /** Unknown or unclassified error. */
583
585
  Unknown: "unknown"
584
586
  };
@@ -647,6 +649,7 @@ var INTERNAL_STATUS_CODES = {
647
649
  [ERROR_CATEGORY.FileOperation]: "fileOperation",
648
650
  [ERROR_CATEGORY.Plugin]: "plugin",
649
651
  [ERROR_CATEGORY.Quota]: "quota",
652
+ [ERROR_CATEGORY.Database]: "database",
650
653
  [ERROR_CATEGORY.Unknown]: "unknown"
651
654
  });
652
655
  var COMMON_OPERATIONS = {
@@ -831,6 +834,11 @@ var HTTP_STATUS = {
831
834
 
832
835
  // src/errors/codes.ts
833
836
  var ERROR_CODES = {
837
+ // ===== Generic/Common Errors =====
838
+ // These are package-agnostic error codes that can be used across all packages
839
+ NOT_IMPLEMENTED: "not.implemented",
840
+ PROVIDER_NOT_IMPLEMENTED: "provider.not.implemented",
841
+ FEATURE_NOT_SUPPORTED: "feature.not.supported",
834
842
  // ===== API Package Errors =====
835
843
  // Client Configuration
836
844
  CLIENT_INITIALIZATION_FAILED: "CLIENT_INITIALIZATION_FAILED",
@@ -1264,6 +1272,7 @@ var ERROR_CODES = {
1264
1272
  DB_INVALID_COUNT: "db.invalid_count",
1265
1273
  // Connection & Network
1266
1274
  DB_CONNECTION_FAILED: "db.connection_failed",
1275
+ DB_CONNECTION_ERROR: "db.connection_error",
1267
1276
  DB_TIMEOUT: "db.timeout",
1268
1277
  // Constraints & Integrity
1269
1278
  DB_CONSTRAINT_VIOLATION: "db.constraint_violation",
@@ -1273,6 +1282,8 @@ var ERROR_CODES = {
1273
1282
  DB_ENTITY_NOT_FOUND: "db.entity_not_found",
1274
1283
  // Migration & Schema
1275
1284
  DB_MIGRATION_FAILED: "db.migration_failed",
1285
+ // Multi-Write Operations
1286
+ DB_MULTI_WRITE_FAILED: "db.multi_write_failed",
1276
1287
  // General
1277
1288
  DB_UNKNOWN_ERROR: "db.unknown_error",
1278
1289
  // ===== Payments Package Errors =====
@@ -1531,6 +1542,31 @@ var API_ERROR_CODES = {
1531
1542
  CDN_PROVIDER_NOT_FOUND: ERROR_CODES.CDN_PROVIDER_NOT_FOUND
1532
1543
  };
1533
1544
  var ERROR_DEFINITIONS = {
1545
+ // ===== Generic/Common Error Definitions =====
1546
+ [ERROR_CODES.NOT_IMPLEMENTED]: {
1547
+ code: ERROR_CODES.NOT_IMPLEMENTED,
1548
+ status: HTTP_STATUS.NOT_IMPLEMENTED,
1549
+ category: ERROR_CATEGORY.System,
1550
+ userMessage: "errors.not_implemented",
1551
+ severity: ERROR_SEVERITY.Medium,
1552
+ retryable: false
1553
+ },
1554
+ [ERROR_CODES.PROVIDER_NOT_IMPLEMENTED]: {
1555
+ code: ERROR_CODES.PROVIDER_NOT_IMPLEMENTED,
1556
+ status: HTTP_STATUS.NOT_IMPLEMENTED,
1557
+ category: ERROR_CATEGORY.System,
1558
+ userMessage: "errors.provider.not_implemented",
1559
+ severity: ERROR_SEVERITY.Medium,
1560
+ retryable: false
1561
+ },
1562
+ [ERROR_CODES.FEATURE_NOT_SUPPORTED]: {
1563
+ code: ERROR_CODES.FEATURE_NOT_SUPPORTED,
1564
+ status: HTTP_STATUS.NOT_IMPLEMENTED,
1565
+ category: ERROR_CATEGORY.System,
1566
+ userMessage: "errors.feature.not_supported",
1567
+ severity: ERROR_SEVERITY.Low,
1568
+ retryable: false
1569
+ },
1534
1570
  // ===== API Package Error Definitions =====
1535
1571
  // Authentication
1536
1572
  [ERROR_CODES.AUTH_UNAUTHORIZED]: {
@@ -4835,6 +4871,22 @@ var ERROR_DEFINITIONS = {
4835
4871
  severity: ERROR_SEVERITY.High,
4836
4872
  retryable: true
4837
4873
  },
4874
+ [ERROR_CODES.DB_CONNECTION_ERROR]: {
4875
+ code: ERROR_CODES.DB_CONNECTION_ERROR,
4876
+ status: HTTP_STATUS.SERVICE_UNAVAILABLE,
4877
+ category: ERROR_CATEGORY.Network,
4878
+ userMessage: "db.connection.error",
4879
+ severity: ERROR_SEVERITY.High,
4880
+ retryable: true
4881
+ },
4882
+ [ERROR_CODES.DB_MULTI_WRITE_FAILED]: {
4883
+ code: ERROR_CODES.DB_MULTI_WRITE_FAILED,
4884
+ status: HTTP_STATUS.INTERNAL_SERVER_ERROR,
4885
+ category: ERROR_CATEGORY.Database,
4886
+ userMessage: "db.multi_write.failed",
4887
+ severity: ERROR_SEVERITY.High,
4888
+ retryable: false
4889
+ },
4838
4890
  [ERROR_CODES.DB_TIMEOUT]: {
4839
4891
  code: ERROR_CODES.DB_TIMEOUT,
4840
4892
  status: HTTP_STATUS.REQUEST_TIMEOUT,