@plyaz/types 1.7.21 → 1.7.23

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.
@@ -2,11 +2,14 @@
2
2
  * API Client Types
3
3
  * Defines the client interface and options
4
4
  */
5
- import type { ApiHandlerMethods } from 'fetchff';
5
+ import type { ApiHandlerMethods, FetchResponse, RequestConfig, ResponseError } from 'fetchff';
6
6
  import type { ApiConfig } from '../config';
7
- import type { ConfigUpdateStrategy, HandlerStrategy } from '../events';
7
+ import type { ConfigUpdateStrategy, EventScopeWithTemporary, HandlerStrategy } from '../events';
8
8
  import type { EndpointTypes } from '../endpoints';
9
9
  import type { UnknownRecord } from 'type-fest';
10
+ import type { NETWORK_QUALITY, NetworkInfo } from '../network';
11
+ import type { ConfigConflict, DebugInfo } from '../debugger';
12
+ import type { ApiPackageErrorLike } from '../errors';
10
13
  /**
11
14
  * Options for creating an API client
12
15
  * Endpoints are automatically included from src/api/endpoints
@@ -146,3 +149,76 @@ export interface TrackConfigUpdateParams {
146
149
  /** Timestamp when the update started */
147
150
  startTime: number;
148
151
  }
152
+ /**
153
+ * ClientEventManager Interface
154
+ * Defines the contract for client event management
155
+ *
156
+ * @template TEventManager - The event manager type (should have a getEmitter() method)
157
+ */
158
+ export interface ClientEventManagerLike<TEventManager> {
159
+ readonly emitter: TEventManager extends {
160
+ getEmitter(): infer E;
161
+ } ? E : never;
162
+ addHandler(event: string, handler: Function | Function[], options?: HandlerOptions): () => void;
163
+ updateConfig(updates: Partial<ApiConfig>, options?: UpdateConfigOptions): void;
164
+ clearTemporaryOverrides(): void;
165
+ checkConflicts(): ConfigConflict[];
166
+ getDebugInfo(): DebugInfo;
167
+ startMonitoring(): void;
168
+ stopMonitoring(): void;
169
+ isMonitoring(): boolean;
170
+ getEventStats(): {
171
+ totalEvents: number;
172
+ totalListeners: number;
173
+ listenerCount: number;
174
+ recentEvents: Array<{
175
+ type: string;
176
+ timestamp: number;
177
+ data?: unknown;
178
+ }>;
179
+ overrideCount: number;
180
+ eventCountsByType: Record<string, number>;
181
+ };
182
+ getActiveScopes(): EventScopeWithTemporary[];
183
+ emitError(error: ApiPackageErrorLike): void;
184
+ emitRequestStart(config: RequestConfig): void;
185
+ emitResponseReceived<TData = unknown>(response: FetchResponse<TData>): void;
186
+ emitRetryAttempt<TResponse = unknown>(error: ResponseError<TResponse>, attemptNumber: number, config?: RequestConfig): void;
187
+ dispose(): void;
188
+ }
189
+ /**
190
+ * Extended API client with event methods
191
+ */
192
+ /**
193
+ * API configuration with additional metadata for debugging and inspection
194
+ */
195
+ export interface ApiConfigWithMetadata extends ApiConfig {
196
+ clientId?: string;
197
+ createdAt?: string;
198
+ lastUpdatedAt?: string;
199
+ updateCount?: number;
200
+ networkInfo?: NetworkInfo;
201
+ networkQuality?: NETWORK_QUALITY;
202
+ activeOverrides?: string[];
203
+ conflictDetection?: boolean;
204
+ configHierarchy?: {
205
+ hasGlobalConfig: boolean;
206
+ hasClientConfig: boolean;
207
+ hasTemporaryOverrides: boolean;
208
+ configOverrideStrategy?: ConfigUpdateStrategy;
209
+ };
210
+ }
211
+ export type ApiClientWithEvents<TEventManager, EndpointsList = UnknownRecord> = ApiClientInstance<EndpointsList> & {
212
+ eventManager: ClientEventManagerLike<TEventManager>;
213
+ on(event: string, handler: Function): () => void;
214
+ off(event: string, handler: Function): void;
215
+ checkConflicts(): ConfigConflict[];
216
+ getDebugInfo(): DebugInfo;
217
+ startMonitoring(): void;
218
+ stopMonitoring(): void;
219
+ isMonitoring(): boolean;
220
+ dispose(): void;
221
+ updateConfig(updates: Partial<ApiClientOptions>, options?: UpdateConfigOptions): void;
222
+ clearTemporaryOverrides(): void;
223
+ getConfig(): ApiConfigWithMetadata;
224
+ };
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import type { ResponseError, RequestConfig } from 'fetchff';
9
9
  import type { ERROR_CATEGORY, ErrorDetail, ErrorResponse } from '../../errors';
10
- import type { API_ERROR_CODES, OPERATIONS, ERROR_FIELDS, STORAGE_TYPES } from '..';
10
+ import type { API_ERROR_CODES, OPERATIONS, ERROR_FIELDS, STORAGE_TYPES, ApiClientInstance } from '..';
11
11
  /**
12
12
  * Typed constants as types for convenience
13
13
  */
@@ -226,3 +226,15 @@ export interface ErrorHandlerOptions {
226
226
  */
227
227
  strategy?: 'merge' | 'replace' | 'prepend' | 'append';
228
228
  }
229
+ /**
230
+ * Options for creating an ApiPackageError
231
+ */
232
+ export interface ApiPackageErrorOptions<EndpointsList> {
233
+ responseError?: ResponseError;
234
+ statusCode?: number;
235
+ errors?: ErrorDetail<unknown, unknown, unknown>[];
236
+ correlationId?: string;
237
+ cause?: Error;
238
+ context?: ErrorContext;
239
+ clientContext?: ApiClientInstance<EndpointsList>;
240
+ }
@@ -157,7 +157,7 @@ export interface HeaderValidationResult {
157
157
  /**
158
158
  * Build enriched context headers from request context
159
159
  */
160
- export interface RequestContext {
160
+ export interface RequestContext<EndpointsList> {
161
161
  request?: {
162
162
  headers?: Record<string, string | string[] | undefined>;
163
163
  ip?: string;
@@ -165,7 +165,7 @@ export interface RequestContext {
165
165
  url?: string;
166
166
  [key: string]: unknown;
167
167
  };
168
- clientContext?: ApiClientInstance;
168
+ clientContext?: ApiClientInstance<EndpointsList>;
169
169
  [key: string]: unknown;
170
170
  }
171
171
  /**