@bereasoftware/nexa 1.2.0 → 1.4.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/README.en.md +179 -335
- package/README.md +177 -22
- package/dist/bereasoftware-nexa-1.4.0.tgz +0 -0
- package/dist/nexa.cjs.js +461 -1
- package/dist/nexa.cjs.js.map +1 -1
- package/dist/nexa.es.js +1111 -892
- package/dist/nexa.es.js.map +1 -1
- package/dist/nexa.iife.js +461 -1
- package/dist/nexa.iife.js.map +1 -1
- package/dist/nexa.umd.js +461 -1
- package/dist/nexa.umd.js.map +1 -1
- package/dist/types/dev-overlay/index.d.ts +15 -0
- package/dist/types/dev-overlay/overlay.d.ts +30 -0
- package/dist/types/dev-overlay/tracker.d.ts +16 -0
- package/dist/types/dev-overlay/types.d.ts +33 -0
- package/dist/types/http-client/http-client.d.ts +51 -23
- package/dist/types/http-client/index.d.ts +2 -2
- package/dist/types/http-client/node-http-adapter.d.ts +7 -2
- package/dist/types/index.d.ts +6 -3
- package/dist/types/realtime/plugin.d.ts +5 -1
- package/dist/types/realtime/sse-client.d.ts +4 -1
- package/dist/types/realtime/websocket-client.d.ts +4 -1
- package/dist/types/types/index.d.ts +50 -44
- package/dist/types/utils/index.d.ts +7 -71
- package/package.json +31 -25
- package/dist/bereasoftware-nexa-1.2.0.tgz +0 -0
- package/dist/types/testing/index.d.ts +0 -5
- package/dist/types/testing/mock-client.d.ts +0 -152
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { RequestTracker } from './tracker';
|
|
2
|
+
export { DevOverlayUI } from './overlay';
|
|
3
|
+
export type { TrackedRequest, DevMetrics, DevOverlayConfig } from './types';
|
|
4
|
+
import { RequestTracker } from './tracker';
|
|
5
|
+
import { DevOverlayUI } from './overlay';
|
|
6
|
+
import type { DevOverlayConfig } from './types';
|
|
7
|
+
export declare function createDevOverlay(config?: DevOverlayConfig): {
|
|
8
|
+
tracker: RequestTracker;
|
|
9
|
+
ui: DevOverlayUI;
|
|
10
|
+
};
|
|
11
|
+
export declare function getDevOverlay(): {
|
|
12
|
+
tracker: RequestTracker | null;
|
|
13
|
+
ui: DevOverlayUI | null;
|
|
14
|
+
};
|
|
15
|
+
export declare function destroyDevOverlay(): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RequestTracker } from './tracker';
|
|
2
|
+
export declare class DevOverlayUI {
|
|
3
|
+
private panel;
|
|
4
|
+
private tracker;
|
|
5
|
+
private visible;
|
|
6
|
+
private selectedRequest;
|
|
7
|
+
private config;
|
|
8
|
+
private searchQuery;
|
|
9
|
+
private removeTrackerListener;
|
|
10
|
+
private keyboardShortcutHandler;
|
|
11
|
+
private globalKeyboardHandler;
|
|
12
|
+
constructor(tracker: RequestTracker);
|
|
13
|
+
show(): void;
|
|
14
|
+
hide(): void;
|
|
15
|
+
toggle(): void;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
private setupKeyboardShortcut;
|
|
18
|
+
private createPanel;
|
|
19
|
+
private bindEvents;
|
|
20
|
+
private render;
|
|
21
|
+
private renderMetricsBar;
|
|
22
|
+
private renderRequestList;
|
|
23
|
+
private renderMetrics;
|
|
24
|
+
private showDetail;
|
|
25
|
+
private showMainView;
|
|
26
|
+
private retrySelected;
|
|
27
|
+
private truncateUrl;
|
|
28
|
+
private formatJson;
|
|
29
|
+
private canUseDOM;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TrackedRequest, DevMetrics, DevOverlayConfig } from './types';
|
|
2
|
+
export declare class RequestTracker {
|
|
3
|
+
private history;
|
|
4
|
+
private maxHistory;
|
|
5
|
+
private listeners;
|
|
6
|
+
private startTime;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(config?: DevOverlayConfig);
|
|
9
|
+
track(request: Omit<TrackedRequest, 'id' | 'timestamp'>): TrackedRequest;
|
|
10
|
+
getHistory(): TrackedRequest[];
|
|
11
|
+
getMetrics(): DevMetrics;
|
|
12
|
+
clear(): void;
|
|
13
|
+
onChange(listener: (request: TrackedRequest) => void): () => void;
|
|
14
|
+
getConfig(): Required<DevOverlayConfig>;
|
|
15
|
+
private generateId;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface TrackedRequest {
|
|
2
|
+
id: string;
|
|
3
|
+
method: string;
|
|
4
|
+
url: string;
|
|
5
|
+
status?: number;
|
|
6
|
+
duration: number;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
cached: boolean;
|
|
9
|
+
ok: boolean;
|
|
10
|
+
code?: string;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
responseHeaders?: Record<string, string>;
|
|
14
|
+
retryCount: number;
|
|
15
|
+
}
|
|
16
|
+
export interface DevMetrics {
|
|
17
|
+
totalRequests: number;
|
|
18
|
+
successfulRequests: number;
|
|
19
|
+
failedRequests: number;
|
|
20
|
+
cachedRequests: number;
|
|
21
|
+
avgDuration: number;
|
|
22
|
+
maxDuration: number;
|
|
23
|
+
minDuration: number;
|
|
24
|
+
requestsPerSecond: number;
|
|
25
|
+
slowestRequests: TrackedRequest[];
|
|
26
|
+
}
|
|
27
|
+
export interface DevOverlayConfig {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
maxHistory?: number;
|
|
30
|
+
keyboardShortcut?: string;
|
|
31
|
+
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
32
|
+
theme?: 'dark' | 'light';
|
|
33
|
+
}
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client Implementation
|
|
3
|
+
* Superior to fetch + axios:
|
|
4
|
+
*
|
|
5
|
+
* vs fetch:
|
|
6
|
+
* ✓ Automatic JSON parsing + error handling via Result<T,E>
|
|
7
|
+
* ✓ Interceptors, retry, cache, timeout built-in
|
|
8
|
+
* ✓ Progress tracking for uploads/downloads
|
|
9
|
+
* ✓ Path parameter interpolation (/users/:id)
|
|
10
|
+
* ✓ Request lifecycle hooks (onStart, onSuccess, onError, onFinally, onRetry)
|
|
11
|
+
* ✓ Auto content-type detection (FormData, Blob, URLSearchParams, etc.)
|
|
12
|
+
* ✓ Concurrent request limiting (rate limiter)
|
|
13
|
+
*
|
|
14
|
+
* vs axios:
|
|
15
|
+
* ✓ Zero dependencies (~3KB gzipped vs axios ~13KB)
|
|
16
|
+
* ✓ Result<T,E> monad — no try/catch needed, type-safe error handling
|
|
17
|
+
* ✓ Built-in request deduplication
|
|
18
|
+
* ✓ Streaming support with chunk callbacks
|
|
19
|
+
* ✓ Plugin architecture (SOLID)
|
|
20
|
+
* ✓ Middleware pipeline (Express/Koa-like)
|
|
21
|
+
* ✓ Circuit breaker retry strategy
|
|
22
|
+
* ✓ Response duration tracking
|
|
23
|
+
* ✓ Modern ESM-first with tree-shaking
|
|
24
|
+
*
|
|
25
|
+
* SOLID Principles:
|
|
26
|
+
* - S: HttpClient → HTTP communication
|
|
27
|
+
* - O: Extensible via interceptors, strategies, plugins
|
|
28
|
+
* - L: Liskov — implementations interchange without breaking
|
|
29
|
+
* - I: Interface Segregation — small focused interfaces
|
|
30
|
+
* - D: Dependency Inversion — depends on abstractions (IHttpClient)
|
|
31
|
+
*/
|
|
32
|
+
import type { IHttpClient, HttpRequestConfig, HttpResponse, HttpErrorDetails, RequestInterceptor, ResponseInterceptor, HttpClientConfig, PaginateOptions, PollOptions, Disposer, Result } from '../types';
|
|
2
33
|
/**
|
|
3
34
|
* Main HTTP Client Implementation
|
|
4
35
|
* Combines fetch API with axios-like convenience + modern features
|
|
@@ -7,23 +38,29 @@ export declare class HttpClient implements IHttpClient {
|
|
|
7
38
|
private requestInterceptors;
|
|
8
39
|
private responseInterceptors;
|
|
9
40
|
private cache;
|
|
41
|
+
private devTracker;
|
|
10
42
|
private config;
|
|
11
43
|
private requestQueue;
|
|
12
44
|
private pendingRequests;
|
|
13
45
|
constructor(config?: HttpClientConfig);
|
|
14
|
-
private logDebug;
|
|
15
46
|
/**
|
|
16
47
|
* Core request method — all others delegate to this
|
|
17
|
-
* Pipeline: hooks → cache → interceptors →
|
|
48
|
+
* Pipeline: hooks → cache → interceptors → fetch → parse → validate → transform → interceptors → cache → hooks
|
|
49
|
+
* Fast path: when no features are used, goes directly to fetch
|
|
18
50
|
*/
|
|
19
51
|
request<T = unknown>(config: HttpRequestConfig): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Fast path — minimal overhead for simple requests without features
|
|
54
|
+
* No interceptors, cache, hooks, retry, validate, transform, queue, progress, or signal
|
|
55
|
+
*/
|
|
56
|
+
private fastPath;
|
|
57
|
+
get<T = unknown>(url: string, config?: Omit<HttpRequestConfig, 'url' | 'method'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
58
|
+
post<T = unknown>(url: string, body?: unknown, config?: Omit<HttpRequestConfig, 'url' | 'method' | 'body'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
59
|
+
put<T = unknown>(url: string, body?: unknown, config?: Omit<HttpRequestConfig, 'url' | 'method' | 'body'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
60
|
+
patch<T = unknown>(url: string, body?: unknown, config?: Omit<HttpRequestConfig, 'url' | 'method' | 'body'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
61
|
+
delete<T = unknown>(url: string, config?: Omit<HttpRequestConfig, 'url' | 'method'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
62
|
+
head(url: string, config?: Omit<HttpRequestConfig, 'url' | 'method'>): Promise<Result<HttpResponse<void>, HttpErrorDetails>>;
|
|
63
|
+
options(url: string, config?: Omit<HttpRequestConfig, 'url' | 'method'>): Promise<Result<HttpResponse<void>, HttpErrorDetails>>;
|
|
27
64
|
addRequestInterceptor(interceptor: RequestInterceptor): Disposer;
|
|
28
65
|
addResponseInterceptor(interceptor: ResponseInterceptor): Disposer;
|
|
29
66
|
clearInterceptors(): void;
|
|
@@ -65,7 +102,7 @@ export declare class HttpClient implements IHttpClient {
|
|
|
65
102
|
* }
|
|
66
103
|
* ```
|
|
67
104
|
*/
|
|
68
|
-
paginate<T = unknown>(url: string, options: PaginateOptions<T>, config?: Omit<HttpRequestConfig,
|
|
105
|
+
paginate<T = unknown>(url: string, options: PaginateOptions<T>, config?: Omit<HttpRequestConfig, 'url' | 'method'>): AsyncGenerator<T[]>;
|
|
69
106
|
/**
|
|
70
107
|
* Poll an endpoint until a condition is met.
|
|
71
108
|
* Returns the final response that satisfied `until()`.
|
|
@@ -80,33 +117,24 @@ export declare class HttpClient implements IHttpClient {
|
|
|
80
117
|
* });
|
|
81
118
|
* ```
|
|
82
119
|
*/
|
|
83
|
-
poll<T = unknown>(url: string, options: PollOptions<T>, config?: Omit<HttpRequestConfig,
|
|
120
|
+
poll<T = unknown>(url: string, options: PollOptions<T>, config?: Omit<HttpRequestConfig, 'url' | 'method'>): Promise<Result<HttpResponse<T>, HttpErrorDetails>>;
|
|
84
121
|
private buildRequest;
|
|
85
122
|
private buildUrl;
|
|
86
|
-
/**
|
|
87
|
-
* Apply transformRequest functions to the request body and headers.
|
|
88
|
-
* Combines global transformRequest (from client config) and request-specific transformRequest.
|
|
89
|
-
* Mutates headers object in place (axios-style).
|
|
90
|
-
*/
|
|
91
|
-
private applyTransformRequestToRequest;
|
|
92
123
|
private getCacheKey;
|
|
93
124
|
private fetchWithTimeout;
|
|
94
125
|
/**
|
|
95
126
|
* Wraps response body with a progress-tracking ReadableStream
|
|
96
127
|
*/
|
|
97
128
|
private trackDownloadProgress;
|
|
98
|
-
/**
|
|
99
|
-
* Wraps a promise with a timeout. If the timeout elapses before the promise resolves,
|
|
100
|
-
* rejects with a TimeoutError.
|
|
101
|
-
*/
|
|
102
|
-
private withTimeout;
|
|
103
129
|
private parseResponse;
|
|
104
130
|
private parseBody;
|
|
105
131
|
private normalizeError;
|
|
106
132
|
private isHttpErrorDetails;
|
|
107
133
|
private getMaxAttempts;
|
|
108
134
|
private getRetryStrategy;
|
|
135
|
+
private resolveTimeoutMs;
|
|
109
136
|
private delay;
|
|
137
|
+
private trackDev;
|
|
110
138
|
}
|
|
111
139
|
export declare class HttpError extends Error {
|
|
112
140
|
status: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HTTP Client Plugin - Main Exports
|
|
3
3
|
*/
|
|
4
|
-
export { createHttpClient, HttpClient, HttpError, isHttpError } from './http-client.js';
|
|
4
|
+
export { createHttpClient, HttpClient, HttpError, isHttpError, } from './http-client.js';
|
|
5
5
|
export type { IHttpClient, HttpRequest, HttpRequestConfig, HttpResponse, HttpErrorDetails, RequestInterceptor, ResponseInterceptor, RetryStrategy, CacheStrategy, Validator, Transformer, HttpClientConfig, ResponseType, RequestHooks, ProgressEvent, PaginateOptions, PollOptions, Disposer, Result, } from '../types/index.js';
|
|
6
6
|
export { Ok, Err } from '../types/index.js';
|
|
7
|
-
export { withTimeout, retry, createSchemaValidator, createRequiredFieldsValidator, validatorIsArray, validatorIsObject, transformSnakeToCamel, transformCamelToSnake, transformFlatten, createProjectionTransformer, createWrapperTransformer, AggressiveRetry, ConservativeRetry, CircuitBreakerRetry, CacheStore, createCacheMiddleware, cacheMiddleware, RequestDeduplicator, createDedupeMiddleware, dedupeMiddleware,
|
|
7
|
+
export { withTimeout, retry, createSchemaValidator, createRequiredFieldsValidator, validatorIsArray, validatorIsObject, transformSnakeToCamel, transformCamelToSnake, transformFlatten, createProjectionTransformer, createWrapperTransformer, AggressiveRetry, ConservativeRetry, CircuitBreakerRetry, CacheStore, createCacheMiddleware, cacheMiddleware, RequestDeduplicator, createDedupeMiddleware, dedupeMiddleware, MiddlewarePipeline, createPipeline, type Middleware, type HttpContext, createTypedResponse, createTypedRequest, createTypedApiClient, createTypeGuard, createUrl, createApiUrl, TypedObservable, Defer, type TypedResponse, type ApiEndpoint, type ApiSchema, type Url, type ApiUrl, type FileUrl, type UnionToIntersection, type ResultOf, handleStream, streamToFile, createStreamingMiddleware, streamingMiddleware, type StreamOptions, PluginManager, LoggerPlugin, MetricsPlugin, CachePlugin, DedupePlugin, type Plugin, } from '../utils';
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Node.js HTTP/1.1 adapter using native http/https modules.
|
|
3
|
+
* Supports keep-alive, connection pooling, and other Node-specific options.
|
|
4
|
+
*/
|
|
5
|
+
import type { NodeTransportOptions } from '../types/index.js';
|
|
6
|
+
import type * as Http2Module from 'http2';
|
|
2
7
|
declare class Http2SessionPool {
|
|
3
8
|
private sessions;
|
|
4
9
|
private cleanupInterval;
|
|
@@ -8,7 +13,7 @@ declare class Http2SessionPool {
|
|
|
8
13
|
private startCleanup;
|
|
9
14
|
private cleanup;
|
|
10
15
|
private closeSession;
|
|
11
|
-
getSession(origin: string, options?: NodeTransportOptions): Promise<
|
|
16
|
+
getSession(origin: string, options?: NodeTransportOptions): Promise<Http2Module.ClientHttp2Session>;
|
|
12
17
|
releaseSession(origin: string): void;
|
|
13
18
|
getStats(): {
|
|
14
19
|
sessionCount: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* Combines fetch power + axios convenience with SOLID principles
|
|
4
4
|
*/
|
|
5
5
|
export * from './http-client';
|
|
6
|
-
export * from './realtime
|
|
7
|
-
export
|
|
8
|
-
export
|
|
6
|
+
export * from './realtime';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './utils';
|
|
9
|
+
export { createDevOverlay, getDevOverlay, destroyDevOverlay, } from './dev-overlay';
|
|
10
|
+
export type { TrackedRequest, DevMetrics, DevOverlayConfig, } from './dev-overlay';
|
|
11
|
+
export { RequestTracker } from './dev-overlay';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Real-time plugin for Nexa
|
|
3
|
+
* Provides WebSocket and SSE integration with the plugin system
|
|
4
|
+
*/
|
|
5
|
+
import type { Plugin, PluginManager } from '../utils/index.js';
|
|
2
6
|
/**
|
|
3
7
|
* Real-time plugin that adds WebSocket and SSE event listeners to the plugin manager
|
|
4
8
|
*/
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Server-Sent Events (SSE) client with automatic reconnection and plugin support.
|
|
3
|
+
*/
|
|
4
|
+
import type { SSEOptions, ISSEClient } from '../types/index.js';
|
|
2
5
|
/**
|
|
3
6
|
* Create an SSE client appropriate for the current environment
|
|
4
7
|
*/
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket client with automatic reconnection, heartbeat, and plugin support.
|
|
3
|
+
*/
|
|
4
|
+
import type { WebSocketOptions, IWebSocketClient } from '../types/index.js';
|
|
2
5
|
/**
|
|
3
6
|
* Create a WebSocket client appropriate for the current environment
|
|
4
7
|
*/
|
|
@@ -30,11 +30,11 @@ export interface HttpRequest {
|
|
|
30
30
|
*/
|
|
31
31
|
credentials?: RequestCredentials;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Custom adapter for this request (same signature as fetch).
|
|
34
34
|
*/
|
|
35
35
|
adapter?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* If true (default), automatically converts body to FormData if files are detected.
|
|
38
38
|
*/
|
|
39
39
|
autoFormData?: boolean;
|
|
40
40
|
/**
|
|
@@ -174,31 +174,9 @@ export type HttpTimeout = number | {
|
|
|
174
174
|
*/
|
|
175
175
|
total?: number;
|
|
176
176
|
};
|
|
177
|
-
/**
|
|
178
|
-
* Configuración extendida para solicitudes HTTP.
|
|
179
|
-
* - credentials: controla el envío de cookies/credenciales ('omit' | 'same-origin' | 'include').
|
|
180
|
-
*/
|
|
181
177
|
export interface HttpRequestConfig extends HttpRequest {
|
|
182
|
-
/**
|
|
183
|
-
* Si es true (default), convierte automáticamente el body a FormData si detecta archivos.
|
|
184
|
-
*/
|
|
185
|
-
autoFormData?: boolean;
|
|
186
|
-
/**
|
|
187
|
-
* Compatibilidad con axios: si es true, establece credentials: 'include'; si es false, credentials: 'same-origin'.
|
|
188
|
-
* Si también se especifica credentials, este campo es ignorado.
|
|
189
|
-
*/
|
|
190
|
-
withCredentials?: boolean;
|
|
191
|
-
/**
|
|
192
|
-
* Permite usar un adapter personalizado para la request (firma igual a fetch).
|
|
193
|
-
* Útil para mocks, tests, o entornos especiales.
|
|
194
|
-
*/
|
|
195
|
-
adapter?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
196
|
-
/**
|
|
197
|
-
* Permite transformar el body antes de serializarlo y enviarlo. Similar a axios.transformRequest.
|
|
198
|
-
* Puede ser una función o un array de funciones.
|
|
199
|
-
*/
|
|
200
|
-
transformRequest?: ((data: unknown, headers: Record<string, string>) => unknown) | Array<(data: unknown, headers: Record<string, string>) => unknown>;
|
|
201
178
|
retry?: RetryStrategy | InlineRetryConfig;
|
|
179
|
+
timeout?: HttpTimeout;
|
|
202
180
|
validate?: Validator;
|
|
203
181
|
transform?: Transformer;
|
|
204
182
|
cache?: {
|
|
@@ -209,6 +187,21 @@ export interface HttpRequestConfig extends HttpRequest {
|
|
|
209
187
|
hooks?: RequestHooks;
|
|
210
188
|
onUploadProgress?: (event: ProgressEvent) => void;
|
|
211
189
|
onDownloadProgress?: (event: ProgressEvent) => void;
|
|
190
|
+
/**
|
|
191
|
+
* Axios compatibility: if true, sets credentials: 'include'; if false, credentials: 'same-origin'.
|
|
192
|
+
* If credentials is also specified, this field is ignored.
|
|
193
|
+
*/
|
|
194
|
+
withCredentials?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Allows using a custom adapter for the request (same signature as fetch).
|
|
197
|
+
* Useful for mocks, tests, or special environments.
|
|
198
|
+
*/
|
|
199
|
+
adapter?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
200
|
+
/**
|
|
201
|
+
* Allows transforming the body before serializing and sending it. Similar to axios.transformRequest.
|
|
202
|
+
* Can be a function or an array of functions.
|
|
203
|
+
*/
|
|
204
|
+
transformRequest?: ((data: unknown, headers: Record<string, string>) => unknown) | Array<(data: unknown, headers: Record<string, string>) => unknown>;
|
|
212
205
|
/**
|
|
213
206
|
* Enable debug logging for this request. Overrides global debug setting.
|
|
214
207
|
*/
|
|
@@ -227,6 +220,10 @@ export interface HttpRequestConfig extends HttpRequest {
|
|
|
227
220
|
* Overrides global nodeOptions.
|
|
228
221
|
*/
|
|
229
222
|
nodeOptions?: NodeTransportOptions;
|
|
223
|
+
/**
|
|
224
|
+
* If true (default), automatically converts body to FormData if files are detected.
|
|
225
|
+
*/
|
|
226
|
+
autoFormData?: boolean;
|
|
230
227
|
}
|
|
231
228
|
export interface PaginateOptions<T> {
|
|
232
229
|
/** Extract items from a response page */
|
|
@@ -265,34 +262,35 @@ export interface IHttpClient {
|
|
|
265
262
|
/** Function that removes a previously added interceptor */
|
|
266
263
|
export type Disposer = () => void;
|
|
267
264
|
export interface HttpClientConfig {
|
|
265
|
+
baseURL?: string;
|
|
266
|
+
defaultHeaders?: Record<string, string>;
|
|
267
|
+
defaultTimeout?: HttpTimeout;
|
|
268
|
+
cacheStrategy?: CacheStrategy;
|
|
269
|
+
validateStatus?: (status: number) => boolean;
|
|
270
|
+
maxConcurrent?: number;
|
|
271
|
+
defaultResponseType?: ResponseType;
|
|
272
|
+
defaultHooks?: RequestHooks;
|
|
273
|
+
devTracker?: DevTracker;
|
|
268
274
|
/**
|
|
269
|
-
*
|
|
275
|
+
* Global adapter for all requests (same signature as fetch).
|
|
270
276
|
*/
|
|
271
277
|
adapter?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
272
|
-
baseURL?: string;
|
|
273
|
-
defaultHeaders?: Record<string, string>;
|
|
274
278
|
/**
|
|
275
279
|
* Controls cookie/credential policy for CORS requests. Same as fetch API.
|
|
276
280
|
* 'omit' | 'same-origin' | 'include'
|
|
277
281
|
*/
|
|
278
282
|
credentials?: RequestCredentials;
|
|
279
283
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
284
|
+
* Axios compatibility: if true, sets credentials: 'include'; if false, credentials: 'same-origin'.
|
|
285
|
+
* If credentials is also specified, this field is ignored.
|
|
282
286
|
*/
|
|
283
287
|
withCredentials?: boolean;
|
|
284
|
-
defaultTimeout?: HttpTimeout;
|
|
285
|
-
cacheStrategy?: CacheStrategy;
|
|
286
|
-
validateStatus?: (status: number) => boolean;
|
|
287
|
-
maxConcurrent?: number;
|
|
288
|
-
defaultResponseType?: ResponseType;
|
|
289
|
-
defaultHooks?: RequestHooks;
|
|
290
288
|
/**
|
|
291
|
-
*
|
|
289
|
+
* Allows transforming the body before serializing and sending it by default in all requests.
|
|
292
290
|
*/
|
|
293
291
|
transformRequest?: ((data: unknown, headers: Record<string, string>) => unknown) | Array<(data: unknown, headers: Record<string, string>) => unknown>;
|
|
294
292
|
/**
|
|
295
|
-
*
|
|
293
|
+
* If true (default), automatically converts body to FormData if files are detected.
|
|
296
294
|
*/
|
|
297
295
|
autoFormData?: boolean;
|
|
298
296
|
/**
|
|
@@ -311,12 +309,6 @@ export interface HttpClientConfig {
|
|
|
311
309
|
* - 'deno': Uses Deno's fetch API (Deno environment)
|
|
312
310
|
* - 'bun': Uses Bun's fetch API (Bun environment)
|
|
313
311
|
* - 'cloudflare': Uses Cloudflare Workers fetch API
|
|
314
|
-
*
|
|
315
|
-
* When 'node' or 'http2' is specified, nodeOptions can be used to configure
|
|
316
|
-
* keep-alive, connection pooling, and other Node-specific settings.
|
|
317
|
-
*
|
|
318
|
-
* Note: Node transports are only available in Node.js environments.
|
|
319
|
-
* Deno, Bun, and Cloudflare transports use their respective fetch implementations.
|
|
320
312
|
*/
|
|
321
313
|
transport?: 'fetch' | 'node' | 'http2' | 'deno' | 'bun' | 'cloudflare';
|
|
322
314
|
/**
|
|
@@ -325,6 +317,20 @@ export interface HttpClientConfig {
|
|
|
325
317
|
*/
|
|
326
318
|
nodeOptions?: NodeTransportOptions;
|
|
327
319
|
}
|
|
320
|
+
export interface DevTracker {
|
|
321
|
+
track(request: {
|
|
322
|
+
method: string;
|
|
323
|
+
url: string;
|
|
324
|
+
status?: number;
|
|
325
|
+
duration: number;
|
|
326
|
+
cached: boolean;
|
|
327
|
+
ok: boolean;
|
|
328
|
+
code?: string;
|
|
329
|
+
headers: Record<string, string>;
|
|
330
|
+
body?: unknown;
|
|
331
|
+
retryCount: number;
|
|
332
|
+
}): void;
|
|
333
|
+
}
|
|
328
334
|
/**
|
|
329
335
|
* WebSocket connection options
|
|
330
336
|
*/
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client Utilities
|
|
3
|
+
* Common validators, transformers, and helpers
|
|
4
|
+
*/
|
|
5
|
+
import type { Validator, Transformer, RetryStrategy, HttpErrorDetails, IHttpClient } from '../types';
|
|
2
6
|
/**
|
|
3
7
|
* Schema validator using simple checks (can be replaced with Zod, Yup, etc)
|
|
4
8
|
*/
|
|
@@ -129,43 +133,6 @@ export declare function createDedupeMiddleware(options?: {
|
|
|
129
133
|
* Pre-configured deduplication middleware for GET requests
|
|
130
134
|
*/
|
|
131
135
|
export declare const dedupeMiddleware: Middleware<HttpContext>;
|
|
132
|
-
/**
|
|
133
|
-
* Rate limiting middleware factory - limits requests per time window
|
|
134
|
-
*/
|
|
135
|
-
export declare function createRateLimitMiddleware(options?: {
|
|
136
|
-
/** Maximum number of requests per window */
|
|
137
|
-
maxRequests: number;
|
|
138
|
-
/** Time window in milliseconds (default: 60000 = 1 minute) */
|
|
139
|
-
windowMs?: number;
|
|
140
|
-
/** Function to generate rate limit key (default: uses request URL) */
|
|
141
|
-
keyGenerator?: (ctx: HttpContext) => string;
|
|
142
|
-
/** Custom error response when limit is exceeded (default: 429 Too Many Requests) */
|
|
143
|
-
errorResponse?: {
|
|
144
|
-
status: number;
|
|
145
|
-
body: unknown;
|
|
146
|
-
};
|
|
147
|
-
}): Middleware<HttpContext>;
|
|
148
|
-
/**
|
|
149
|
-
* Pre-configured rate limit middleware: 100 requests per minute per endpoint
|
|
150
|
-
*/
|
|
151
|
-
export declare const rateLimitMiddleware: Middleware<HttpContext>;
|
|
152
|
-
/**
|
|
153
|
-
* Circuit breaker middleware factory - prevents cascading failures
|
|
154
|
-
*/
|
|
155
|
-
export declare function createCircuitBreakerMiddleware(options?: {
|
|
156
|
-
/** Failure threshold to open circuit (default: 5) */
|
|
157
|
-
failureThreshold?: number;
|
|
158
|
-
/** Time in ms to wait before attempting again (default: 30000) */
|
|
159
|
-
resetTimeout?: number;
|
|
160
|
-
/** Function to determine if a response is a failure (default: status >= 500) */
|
|
161
|
-
isFailure?: (ctx: HttpContext) => boolean;
|
|
162
|
-
/** Function to generate circuit key (default: uses request URL) */
|
|
163
|
-
keyGenerator?: (ctx: HttpContext) => string;
|
|
164
|
-
}): Middleware<HttpContext>;
|
|
165
|
-
/**
|
|
166
|
-
* Pre-configured circuit breaker middleware
|
|
167
|
-
*/
|
|
168
|
-
export declare const circuitBreakerMiddleware: Middleware<HttpContext>;
|
|
169
136
|
/**
|
|
170
137
|
* HTTP Context passed through middleware chain
|
|
171
138
|
*/
|
|
@@ -239,7 +206,7 @@ export type ApiSchema = Record<string, ApiEndpoint>;
|
|
|
239
206
|
* Create a typed API client from schema
|
|
240
207
|
*/
|
|
241
208
|
export declare function createTypedApiClient<T extends ApiSchema>(schema: T): {
|
|
242
|
-
request: <K extends keyof T>(client: IHttpClient, endpoint: K, data?: T[K] extends ApiEndpoint<infer TReq,
|
|
209
|
+
request: <K extends keyof T>(client: IHttpClient, endpoint: K, data?: T[K] extends ApiEndpoint<infer TReq, unknown> ? TReq : never) => Promise<T[K] extends ApiEndpoint<unknown, infer TRes> ? TRes : never>;
|
|
243
210
|
};
|
|
244
211
|
/**
|
|
245
212
|
* Observable-like response wrapper for reactive patterns
|
|
@@ -260,7 +227,7 @@ export declare class TypedObservable<T> {
|
|
|
260
227
|
/**
|
|
261
228
|
* Union type helper - extracts success/error types
|
|
262
229
|
*/
|
|
263
|
-
export type UnionToIntersection<U> = (U extends
|
|
230
|
+
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
264
231
|
/**
|
|
265
232
|
* Result type extractor for discriminated unions
|
|
266
233
|
*/
|
|
@@ -426,35 +393,4 @@ export declare class DedupePlugin implements Plugin {
|
|
|
426
393
|
name: string;
|
|
427
394
|
setup(manager: PluginManager): void;
|
|
428
395
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Rate limiting plugin - adds rate limiting middleware
|
|
431
|
-
*/
|
|
432
|
-
export declare class RateLimitPlugin implements Plugin {
|
|
433
|
-
name: string;
|
|
434
|
-
private options;
|
|
435
|
-
constructor(options?: {
|
|
436
|
-
maxRequests?: number;
|
|
437
|
-
windowMs?: number;
|
|
438
|
-
keyGenerator?: (ctx: HttpContext) => string;
|
|
439
|
-
errorResponse?: {
|
|
440
|
-
status: number;
|
|
441
|
-
body: unknown;
|
|
442
|
-
};
|
|
443
|
-
});
|
|
444
|
-
setup(manager: PluginManager): void;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Circuit breaker plugin - adds circuit breaker middleware
|
|
448
|
-
*/
|
|
449
|
-
export declare class CircuitBreakerPlugin implements Plugin {
|
|
450
|
-
name: string;
|
|
451
|
-
private options;
|
|
452
|
-
constructor(options?: {
|
|
453
|
-
failureThreshold?: number;
|
|
454
|
-
resetTimeout?: number;
|
|
455
|
-
isFailure?: (ctx: HttpContext) => boolean;
|
|
456
|
-
keyGenerator?: (ctx: HttpContext) => string;
|
|
457
|
-
});
|
|
458
|
-
setup(manager: PluginManager): void;
|
|
459
|
-
}
|
|
460
396
|
export type { HttpErrorDetails };
|