reqforge 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/types/index.d.ts +118 -0
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "reqforge",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A lightweight, flexible HTTP client library with request interception, automatic retry, and logging capabilities, designed for modern web applications.",
5
5
  "main": "src/index.js",
6
+ "types": "types/index.d.ts",
6
7
  "scripts": {
7
8
  "test": "echo \"No tests yet\" && exit 0"
8
9
  },
@@ -0,0 +1,118 @@
1
+ declare module 'reqforge' {
2
+ // Config
3
+ export const config: {
4
+ getBaseURL(): string;
5
+ API_VERSION: string;
6
+ defaultConfig: RequestConfig;
7
+ mergeConfig(customConfig?: Partial<RequestConfig>): RequestConfig;
8
+ };
9
+
10
+ // Request
11
+ export const request: {
12
+ sendRequest(endpoint: string, data?: any, options?: RequestOptions): Promise<Response>;
13
+ get(endpoint: string, options?: RequestOptions): Promise<Response>;
14
+ post(endpoint: string, data?: any, options?: RequestOptions): Promise<Response>;
15
+ put(endpoint: string, data?: any, options?: RequestOptions): Promise<Response>;
16
+ del(endpoint: string, options?: RequestOptions): Promise<Response>;
17
+ };
18
+
19
+ // Logger
20
+ export class Logger {
21
+ constructor(prefix?: string);
22
+ log(message: string): void;
23
+ info(message: string): void;
24
+ warn(message: string): void;
25
+ error(message: string): void;
26
+ }
27
+
28
+ // Auth
29
+ export const auth: {
30
+ login(username: string, password: string): Promise<any>;
31
+ logout(): Promise<void>;
32
+ getToken(): string | null;
33
+ setToken(token: string): void;
34
+ isAuthenticated(): boolean;
35
+ };
36
+
37
+ // Errors
38
+ export const errors: {
39
+ ReqForgeError: typeof ReqForgeError;
40
+ NetworkError: typeof NetworkError;
41
+ TimeoutError: typeof TimeoutError;
42
+ AuthError: typeof AuthError;
43
+ ValidationError: typeof ValidationError;
44
+ ErrorCodes: ErrorCodes;
45
+ createErrorFromResponse(response: Response): ReqForgeError;
46
+ };
47
+
48
+ // Retry
49
+ export const retry: {
50
+ withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
51
+ calculateBackoff(attempt: number, baseDelay?: number, maxDelay?: number): number;
52
+ };
53
+
54
+ // Interceptor
55
+ export const interceptor: {
56
+ createRequestInterceptor(): InterceptorManager;
57
+ createResponseInterceptor(): InterceptorManager;
58
+ };
59
+
60
+ // Cache
61
+ export const cache: {
62
+ MemoryCache: typeof MemoryCache;
63
+ createCacheKey(url: string, params?: Record<string, any>): string;
64
+ };
65
+
66
+ // Types
67
+ interface RequestConfig {
68
+ baseURL: string;
69
+ timeout: number;
70
+ headers: Record<string, string>;
71
+ }
72
+
73
+ interface RequestOptions {
74
+ method?: string;
75
+ headers?: Record<string, string>;
76
+ timeout?: number;
77
+ }
78
+
79
+ interface RetryOptions {
80
+ maxRetries?: number;
81
+ delay?: number;
82
+ backoff?: number;
83
+ shouldRetry?: (error: Error) => boolean;
84
+ }
85
+
86
+ class ReqForgeError extends Error {
87
+ code: string;
88
+ }
89
+
90
+ class NetworkError extends ReqForgeError {}
91
+ class TimeoutError extends ReqForgeError {}
92
+ class AuthError extends ReqForgeError {}
93
+ class ValidationError extends ReqForgeError {}
94
+
95
+ interface ErrorCodes {
96
+ NETWORK_ERROR: string;
97
+ TIMEOUT_ERROR: string;
98
+ AUTH_ERROR: string;
99
+ VALIDATION_ERROR: string;
100
+ UNKNOWN_ERROR: string;
101
+ }
102
+
103
+ class InterceptorManager {
104
+ use(fulfilled: (data: any) => any, rejected?: (error: Error) => any): number;
105
+ eject(id: number): void;
106
+ clear(): void;
107
+ }
108
+
109
+ class MemoryCache {
110
+ constructor(options?: { defaultTTL?: number });
111
+ get(key: string): any | null;
112
+ set(key: string, value: any, ttl?: number): void;
113
+ has(key: string): boolean;
114
+ delete(key: string): void;
115
+ clear(): void;
116
+ size(): number;
117
+ }
118
+ }