@plyaz/config 1.5.1 → 1.5.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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Typed constants for API error handling
3
+ */
4
+ /**
5
+ * Operation types for error context
6
+ */
7
+ export declare const OPERATIONS: {
8
+ readonly STORAGE: "storage";
9
+ readonly RETRIEVAL: "retrieval";
10
+ readonly INVALIDATION: "invalidation";
11
+ readonly ENRICHMENT: "enrichment";
12
+ readonly VALIDATION: "validation";
13
+ readonly PRESET_LOOKUP: "preset-lookup";
14
+ readonly INITIALIZATION: "initialization";
15
+ readonly CONFIGURATION: "configuration";
16
+ readonly REQUEST: "request";
17
+ readonly RESPONSE: "response";
18
+ readonly RETRY: "retry";
19
+ readonly REVALIDATION: "revalidation";
20
+ readonly STRATEGY_EXECUTION: "strategy-execution";
21
+ readonly POLLING: "polling";
22
+ readonly SUBSCRIPTION: "subscription";
23
+ readonly PUBLICATION: "publication";
24
+ readonly DEBUG: "debug";
25
+ readonly DEBUG_TRACKING: "debug-tracking";
26
+ readonly ENDPOINT_BUILD: "endpoint-build";
27
+ readonly TRACKING: "tracking";
28
+ readonly NETWORK_CHECK: "network-check";
29
+ readonly EVENT_HANDLING: "event-handling";
30
+ readonly SERIALIZATION: "serialization";
31
+ readonly DESERIALIZATION: "deserialization";
32
+ readonly REGIONAL_DETECTION: "regional-detection";
33
+ readonly MONITORING: "monitoring";
34
+ readonly CONTEXT_SETUP: "context-setup";
35
+ readonly FALLBACK: "fallback";
36
+ };
37
+ /**
38
+ * Field types for error context
39
+ */
40
+ export declare const ERROR_FIELDS: {
41
+ readonly STORAGE: "storage";
42
+ readonly CACHE: "cache";
43
+ readonly HEADERS: "headers";
44
+ readonly PRESET_NAME: "presetName";
45
+ readonly PRESET_ID: "presetId";
46
+ readonly CONFIG: "config";
47
+ readonly URL: "url";
48
+ readonly METHOD: "method";
49
+ readonly STRATEGY: "strategy";
50
+ readonly RETRY_COUNT: "retryCount";
51
+ readonly MAX_RETRIES: "maxRetries";
52
+ readonly POLLING_INTERVAL: "pollingInterval";
53
+ readonly TOPIC: "topic";
54
+ readonly CHANNEL: "channel";
55
+ readonly ENDPOINT: "endpoint";
56
+ readonly CLIENT: "client";
57
+ readonly NETWORK_TYPE: "networkType";
58
+ readonly TIME_INTERVAL: "timeInterval";
59
+ };
60
+ /**
61
+ * Storage types for API errors
62
+ */
63
+ export declare const STORAGE_TYPES: {
64
+ readonly PRIMARY: "primary";
65
+ readonly FALLBACK: "fallback";
66
+ readonly MEMORY: "memory";
67
+ readonly SESSION: "session";
68
+ readonly LOCAL: "local";
69
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * API Error Constants
3
+ * Re-exports all API error-related constants
4
+ */
5
+ export * from './constants';
@@ -0,0 +1,285 @@
1
+ /**
2
+ * Event Namespace Constants
3
+ * Centralized constants for all event namespaces in the API package
4
+ */
5
+ /**
6
+ * Main event namespaces for the API package
7
+ */
8
+ export declare const EVENT_NAMESPACES: {
9
+ readonly HEADERS: "headers";
10
+ readonly NETWORK: "network";
11
+ readonly ERRORS: "errors";
12
+ readonly DEBUG: "debug";
13
+ readonly CONFIG: "config";
14
+ readonly PERFORMANCE: "performance";
15
+ readonly CLIENT: "client";
16
+ readonly CACHE: "cache";
17
+ readonly POLLING: "polling";
18
+ readonly REQUEST: "request";
19
+ readonly REVALIDATION: "revalidation";
20
+ readonly EVENT_MANAGER: "eventManager";
21
+ };
22
+ /**
23
+ * Header-specific event keys
24
+ */
25
+ export declare const HEADER_EVENTS: {
26
+ readonly CHANGED: "headers:changed";
27
+ readonly ENRICHED: "headers:enriched";
28
+ readonly CONFLICT: "headers:conflict";
29
+ readonly OVERRIDE: "headers:override";
30
+ readonly TRACKED: "headers:tracked";
31
+ readonly MERGED: "headers:merged";
32
+ readonly FILTERED: "headers:filtered";
33
+ readonly VALIDATED: "headers:validated";
34
+ readonly CACHED: "headers:cached";
35
+ readonly CACHE_HIT: "headers:cache:hit";
36
+ readonly CACHE_MISS: "headers:cache:miss";
37
+ readonly ANY: "headers:*";
38
+ };
39
+ /**
40
+ * Network-specific event keys
41
+ */
42
+ export declare const NETWORK_EVENTS: {
43
+ readonly QUALITY_CHANGE: "network:quality:changed";
44
+ readonly INFO_UPDATE: "network:info-update";
45
+ readonly CONFIG_OVERRIDE: "network:config:override";
46
+ readonly CONFIG_RESTORED: "network:config:restored";
47
+ readonly OVERRIDE_CHANGE: "network:override-change";
48
+ readonly PRESET_APPLIED: "network:preset-applied";
49
+ readonly PRESET_CHANGED: "network:preset:changed";
50
+ readonly HINTS_UPDATED: "network:hints:updated";
51
+ readonly AUTO_DETECTION: "network:auto:detection";
52
+ readonly MANUAL_UPDATE: "network:manual:update";
53
+ readonly ANY: "network:*";
54
+ };
55
+ /**
56
+ * Error-specific event keys
57
+ */
58
+ export declare const ERROR_EVENTS: {
59
+ readonly NETWORK_ERROR: "errors:network";
60
+ readonly VALIDATION_ERROR: "errors:validation";
61
+ readonly AUTHENTICATION_ERROR: "errors:authentication";
62
+ readonly AUTHORIZATION_ERROR: "errors:authorization";
63
+ readonly RATE_LIMIT_ERROR: "errors:rate-limit";
64
+ readonly SERVER_ERROR: "errors:server";
65
+ readonly CLIENT_ERROR: "errors:client";
66
+ readonly TIMEOUT_ERROR: "errors:timeout";
67
+ readonly CONFLICT_ERROR: "errors:conflict";
68
+ readonly CACHE_ERROR: "errors:cache";
69
+ readonly HEADERS_ERROR: "errors:headers";
70
+ readonly RETRY_ERROR: "errors:retry";
71
+ readonly STRATEGY_ERROR: "errors:strategy";
72
+ readonly REGIONAL_ERROR: "errors:regional";
73
+ readonly NOT_FOUND_ERROR: "errors:not-found";
74
+ readonly EXTERNAL_SERVICE_ERROR: "errors:external-service";
75
+ readonly UNKNOWN_ERROR: "errors:unknown";
76
+ readonly GENERIC_ERROR: "errors:generic";
77
+ readonly ANY: "errors:*";
78
+ };
79
+ /**
80
+ * Handler scopes for different levels of event handlers
81
+ * These prefixes are used for registering handlers at different priority levels
82
+ * Can be used for any type of handler (error, request, response, debug, etc.)
83
+ *
84
+ * Priority order (lowest to highest):
85
+ * 1. GLOBAL - Set via setGlobalErrorHandlers(), persists across all instances
86
+ * 2. CONFIG - Set via setGlobalConfig({ errorHandlers }), global configuration
87
+ * 3. CLIENT - Set via createApiClient({ errorHandlers }), instance-specific
88
+ * 4. REQUEST/TEMPORARY - Set per-request or via updateConfig(), highest priority
89
+ *
90
+ * Usage:
91
+ * - GLOBAL: For app-wide handlers that should always run (e.g., logging)
92
+ * - CONFIG: For environment-specific handlers (e.g., dev vs prod)
93
+ * - CLIENT: For instance-specific handlers (e.g., per-service client)
94
+ * - REQUEST/TEMPORARY: For request-specific or runtime updates
95
+ *
96
+ * Note: REQUEST and TEMPORARY are aliases - both use 'request' scope
97
+ *
98
+ * Examples of namespaced handlers:
99
+ * - Error handlers: 'global:error', 'config:error', 'client:error'
100
+ * - Debug handlers: 'global:debug', 'config:debug', 'client:debug'
101
+ * - Request handlers: 'global:request', 'config:request', 'client:request'
102
+ */
103
+ export declare const HANDLER_SCOPES: {
104
+ readonly GLOBAL: "global";
105
+ readonly CONFIG: "config";
106
+ readonly CLIENT: "client";
107
+ readonly TEMPORARY: "request";
108
+ readonly REQUEST: "request";
109
+ };
110
+ /**
111
+ * Core event scopes (excluding aliases)
112
+ * These are the actual scope values used by the event system
113
+ */
114
+ export declare const EVENT_SCOPES: readonly ["global", "config", "client", "request"];
115
+ /**
116
+ * All event scopes including 'temporary' alias
117
+ * Used in APIs where 'temporary' provides semantic clarity
118
+ */
119
+ export declare const EVENT_SCOPES_WITH_TEMPORARY: readonly ["global", "config", "client", "request", "temporary"];
120
+ /**
121
+ * Debug-specific event keys
122
+ */
123
+ export declare const DEBUG_EVENTS: {
124
+ readonly CONFIG_CONFLICT: "debug:config-conflict";
125
+ readonly CONFIG_CHANGE: "debug:config-change";
126
+ readonly HEADERS_TRACKED: "debug:headers-tracked";
127
+ readonly NETWORK_OVERRIDE: "debug:network-override";
128
+ readonly NETWORK_STATE_CHANGED: "debug:network-state-changed";
129
+ readonly NETWORK_DATA_CLEARED: "debug:network-data-cleared";
130
+ readonly DEBUG_INFO: "debug:info";
131
+ readonly PERFORMANCE_IMPACT: "debug:performance-impact";
132
+ readonly MONITORING_ALERT: "debug:monitoring-alert";
133
+ readonly CONFIG_TRACKED: "debug:config-tracked";
134
+ readonly CONFLICTS_BATCH: "debug:conflicts-batch";
135
+ readonly EVENT_OPERATION: "debug:event-operation";
136
+ readonly ANY: "debug:*";
137
+ };
138
+ /**
139
+ * Configuration sources - where config updates originate from
140
+ */
141
+ export declare const CONFIG_SOURCES: {
142
+ readonly GLOBAL: "global";
143
+ readonly CREATE_API_CLIENT: "createApiClient";
144
+ readonly UPDATE_CONFIG: "updateConfig";
145
+ readonly MANUAL: "manual";
146
+ readonly ENVIRONMENT: "environment";
147
+ readonly PRESET: "preset";
148
+ readonly NETWORK_AWARE: "networkAware";
149
+ readonly ADAPTIVE: "adaptive";
150
+ };
151
+ /**
152
+ * Configuration-specific event keys
153
+ */
154
+ export declare const CONFIG_EVENTS: {
155
+ readonly GLOBAL_UPDATED: "config:global-updated";
156
+ readonly GLOBAL_RESET: "config:global-reset";
157
+ readonly ENVIRONMENT_CONFIGURED: "config:environment-configured";
158
+ readonly PRESET_APPLIED: "config:preset-applied";
159
+ readonly ANY: "config:*";
160
+ };
161
+ /**
162
+ * Performance-specific event keys
163
+ */
164
+ export declare const PERFORMANCE_EVENTS: {
165
+ readonly REQUEST_START: "performance:request-start";
166
+ readonly REQUEST_COMPLETE: "performance:request-complete";
167
+ readonly RETRY: "performance:retry";
168
+ readonly THRESHOLD_EXCEEDED: "performance:threshold-exceeded";
169
+ readonly OPTIMIZATION_APPLIED: "performance:optimization-applied";
170
+ readonly METRIC_RECORDED: "performance:metric-recorded";
171
+ readonly ANY: "performance:*";
172
+ };
173
+ /**
174
+ * Client-specific event keys
175
+ */
176
+ export declare const CLIENT_EVENTS: {
177
+ readonly CONFLICT: "client:conflict";
178
+ readonly DEBUG: "client:debug";
179
+ readonly CREATED: "client:created";
180
+ readonly ANY: "client:*";
181
+ };
182
+ /**
183
+ * Cache-specific event keys
184
+ */
185
+ export declare const CACHE_EVENTS: {
186
+ readonly HIT: "cache:hit";
187
+ readonly MISS: "cache:miss";
188
+ readonly INVALIDATE: "cache:invalidate";
189
+ readonly ANY: "cache:*";
190
+ };
191
+ /**
192
+ * All event keys combined for easy access
193
+ */
194
+ export declare const ALL_EVENTS: {
195
+ readonly HIT: "cache:hit";
196
+ readonly MISS: "cache:miss";
197
+ readonly INVALIDATE: "cache:invalidate";
198
+ readonly ANY: "cache:*";
199
+ readonly CONFLICT: "client:conflict";
200
+ readonly DEBUG: "client:debug";
201
+ readonly CREATED: "client:created";
202
+ readonly REQUEST_START: "performance:request-start";
203
+ readonly REQUEST_COMPLETE: "performance:request-complete";
204
+ readonly RETRY: "performance:retry";
205
+ readonly THRESHOLD_EXCEEDED: "performance:threshold-exceeded";
206
+ readonly OPTIMIZATION_APPLIED: "performance:optimization-applied";
207
+ readonly METRIC_RECORDED: "performance:metric-recorded";
208
+ readonly GLOBAL_UPDATED: "config:global-updated";
209
+ readonly GLOBAL_RESET: "config:global-reset";
210
+ readonly ENVIRONMENT_CONFIGURED: "config:environment-configured";
211
+ readonly PRESET_APPLIED: "config:preset-applied";
212
+ readonly CONFIG_CONFLICT: "debug:config-conflict";
213
+ readonly CONFIG_CHANGE: "debug:config-change";
214
+ readonly HEADERS_TRACKED: "debug:headers-tracked";
215
+ readonly NETWORK_OVERRIDE: "debug:network-override";
216
+ readonly NETWORK_STATE_CHANGED: "debug:network-state-changed";
217
+ readonly NETWORK_DATA_CLEARED: "debug:network-data-cleared";
218
+ readonly DEBUG_INFO: "debug:info";
219
+ readonly PERFORMANCE_IMPACT: "debug:performance-impact";
220
+ readonly MONITORING_ALERT: "debug:monitoring-alert";
221
+ readonly CONFIG_TRACKED: "debug:config-tracked";
222
+ readonly CONFLICTS_BATCH: "debug:conflicts-batch";
223
+ readonly EVENT_OPERATION: "debug:event-operation";
224
+ readonly NETWORK_ERROR: "errors:network";
225
+ readonly VALIDATION_ERROR: "errors:validation";
226
+ readonly AUTHENTICATION_ERROR: "errors:authentication";
227
+ readonly AUTHORIZATION_ERROR: "errors:authorization";
228
+ readonly RATE_LIMIT_ERROR: "errors:rate-limit";
229
+ readonly SERVER_ERROR: "errors:server";
230
+ readonly CLIENT_ERROR: "errors:client";
231
+ readonly TIMEOUT_ERROR: "errors:timeout";
232
+ readonly CONFLICT_ERROR: "errors:conflict";
233
+ readonly CACHE_ERROR: "errors:cache";
234
+ readonly HEADERS_ERROR: "errors:headers";
235
+ readonly RETRY_ERROR: "errors:retry";
236
+ readonly STRATEGY_ERROR: "errors:strategy";
237
+ readonly REGIONAL_ERROR: "errors:regional";
238
+ readonly NOT_FOUND_ERROR: "errors:not-found";
239
+ readonly EXTERNAL_SERVICE_ERROR: "errors:external-service";
240
+ readonly UNKNOWN_ERROR: "errors:unknown";
241
+ readonly GENERIC_ERROR: "errors:generic";
242
+ readonly QUALITY_CHANGE: "network:quality:changed";
243
+ readonly INFO_UPDATE: "network:info-update";
244
+ readonly CONFIG_OVERRIDE: "network:config:override";
245
+ readonly CONFIG_RESTORED: "network:config:restored";
246
+ readonly OVERRIDE_CHANGE: "network:override-change";
247
+ readonly PRESET_CHANGED: "network:preset:changed";
248
+ readonly HINTS_UPDATED: "network:hints:updated";
249
+ readonly AUTO_DETECTION: "network:auto:detection";
250
+ readonly MANUAL_UPDATE: "network:manual:update";
251
+ readonly CHANGED: "headers:changed";
252
+ readonly ENRICHED: "headers:enriched";
253
+ readonly OVERRIDE: "headers:override";
254
+ readonly TRACKED: "headers:tracked";
255
+ readonly MERGED: "headers:merged";
256
+ readonly FILTERED: "headers:filtered";
257
+ readonly VALIDATED: "headers:validated";
258
+ readonly CACHED: "headers:cached";
259
+ readonly CACHE_HIT: "headers:cache:hit";
260
+ readonly CACHE_MISS: "headers:cache:miss";
261
+ };
262
+ /**
263
+ * Alias for ERROR_EVENTS for backwards compatibility
264
+ */
265
+ export declare const ERROR_EVENT_TYPES: {
266
+ readonly NETWORK_ERROR: "errors:network";
267
+ readonly VALIDATION_ERROR: "errors:validation";
268
+ readonly AUTHENTICATION_ERROR: "errors:authentication";
269
+ readonly AUTHORIZATION_ERROR: "errors:authorization";
270
+ readonly RATE_LIMIT_ERROR: "errors:rate-limit";
271
+ readonly SERVER_ERROR: "errors:server";
272
+ readonly CLIENT_ERROR: "errors:client";
273
+ readonly TIMEOUT_ERROR: "errors:timeout";
274
+ readonly CONFLICT_ERROR: "errors:conflict";
275
+ readonly CACHE_ERROR: "errors:cache";
276
+ readonly HEADERS_ERROR: "errors:headers";
277
+ readonly RETRY_ERROR: "errors:retry";
278
+ readonly STRATEGY_ERROR: "errors:strategy";
279
+ readonly REGIONAL_ERROR: "errors:regional";
280
+ readonly NOT_FOUND_ERROR: "errors:not-found";
281
+ readonly EXTERNAL_SERVICE_ERROR: "errors:external-service";
282
+ readonly UNKNOWN_ERROR: "errors:unknown";
283
+ readonly GENERIC_ERROR: "errors:generic";
284
+ readonly ANY: "errors:*";
285
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Event Constants
3
+ * Re-exports all event-related constants
4
+ */
5
+ export * from './constants';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * API Package Constants
3
+ * Re-exports all API-related constants (events, errors, etc.)
4
+ */
5
+ export * from './events';
6
+ export * from './errors';
7
+ export * from './network';
8
+ export * from './regional';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Network Quality Constants
3
+ */
4
+ /**
5
+ * Network quality levels
6
+ */
7
+ export declare const NETWORK_QUALITY: {
8
+ readonly EXCELLENT: "excellent";
9
+ readonly GOOD: "good";
10
+ readonly FAIR: "fair";
11
+ readonly POOR: "poor";
12
+ readonly OFFLINE: "offline";
13
+ readonly UNKNOWN: "unknown";
14
+ };
15
+ /**
16
+ * Network quality type
17
+ */
18
+ export type NetworkQuality = (typeof NETWORK_QUALITY)[keyof typeof NETWORK_QUALITY];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Network Constants
3
+ * Re-exports all network-related constants
4
+ */
5
+ export * from './constants';
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Regional detection constants
3
+ */
4
+ export declare const REGION_STORAGE_KEY = "@plyaz/api:userRegion";
5
+ /**
6
+ * Confidence levels for region detection
7
+ */
8
+ export declare const CONFIDENCE_LEVELS: {
9
+ readonly CDN_HEADER: 0.95;
10
+ readonly TIMEZONE_DIRECT: 0.9;
11
+ readonly TIMEZONE_PREFIX: 0.8;
12
+ readonly HIGH: 0.8;
13
+ readonly LOCALE_DIRECT: 0.7;
14
+ readonly MEDIUM: 0.7;
15
+ readonly GEOLOCATION: 0.6;
16
+ readonly LOCALE_LANGUAGE: 0.5;
17
+ readonly LOW: 0.5;
18
+ readonly GLOBAL_FALLBACK: 0.3;
19
+ readonly UNKNOWN_FALLBACK: 0.2;
20
+ readonly FINAL_FALLBACK: 0.1;
21
+ };
22
+ /**
23
+ * Geographic coordinates for region detection
24
+ */
25
+ export declare const COORDINATES: {
26
+ readonly EU: {
27
+ readonly MIN_LAT: 35;
28
+ readonly MAX_LAT: 70;
29
+ readonly MIN_LON: -10;
30
+ readonly MAX_LON: 40;
31
+ };
32
+ readonly US: {
33
+ readonly MIN_LAT: 25;
34
+ readonly MAX_LAT: 50;
35
+ readonly MIN_LON: -125;
36
+ readonly MAX_LON: -65;
37
+ };
38
+ readonly US_WEST: {
39
+ readonly MIN_LAT: 32;
40
+ readonly MAX_LAT: 42;
41
+ readonly MIN_LON: -125;
42
+ readonly MAX_LON: -114;
43
+ };
44
+ readonly US_EAST: {
45
+ readonly MIN_LAT: 38;
46
+ readonly MAX_LAT: 45;
47
+ readonly MIN_LON: -80;
48
+ readonly MAX_LON: -70;
49
+ };
50
+ readonly ASIA: {
51
+ readonly MIN_LAT: 18;
52
+ readonly MAX_LAT: 54;
53
+ readonly MIN_LON: 73;
54
+ readonly MAX_LON: 135;
55
+ };
56
+ readonly JAPAN: {
57
+ readonly MIN_LAT: 30;
58
+ readonly MAX_LAT: 46;
59
+ readonly MIN_LON: 129;
60
+ readonly MAX_LON: 146;
61
+ };
62
+ };
63
+ export declare const CACHE_DURATION_MS: number;
64
+ /**
65
+ * Map regions to presets
66
+ */
67
+ export declare const REGION_TO_PRESET: {
68
+ readonly eu: "gdpr";
69
+ readonly us: "ccpa";
70
+ readonly 'us-ca': "ccpa";
71
+ readonly cn: "pipl";
72
+ readonly jp: "appi";
73
+ readonly ca: "global";
74
+ readonly global: "global";
75
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Regional Constants
3
+ * Re-exports all regional-related constants
4
+ */
5
+ export * from './constants';