aziosxjs 0.4.1 → 1.0.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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -267
  3. package/dist/cache/memoryCache.d.ts +1 -0
  4. package/dist/cache/memoryCache.js +7 -1
  5. package/dist/cache/memoryCache.js.map +1 -1
  6. package/dist/core/Azios.d.ts +33 -8
  7. package/dist/core/Azios.js +68 -2
  8. package/dist/core/Azios.js.map +1 -1
  9. package/dist/core/dispatchRequest.js +10 -75
  10. package/dist/core/dispatchRequest.js.map +1 -1
  11. package/dist/index.d.ts +15 -0
  12. package/dist/index.js +50 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/middleware/MiddlewarePipeline.d.ts +54 -0
  15. package/dist/middleware/MiddlewarePipeline.js +122 -0
  16. package/dist/middleware/MiddlewarePipeline.js.map +1 -0
  17. package/dist/middleware/compose.d.ts +1 -0
  18. package/dist/middleware/compose.js +25 -0
  19. package/dist/middleware/compose.js.map +1 -0
  20. package/dist/middleware/middlewareManager.d.ts +4 -0
  21. package/dist/middleware/middlewareManager.js +12 -0
  22. package/dist/middleware/middlewareManager.js.map +1 -0
  23. package/dist/plugins/pluginManager.d.ts +44 -0
  24. package/dist/plugins/pluginManager.js +120 -0
  25. package/dist/plugins/pluginManager.js.map +1 -0
  26. package/dist/runtimes/AdapterFactory.d.ts +22 -0
  27. package/dist/runtimes/AdapterFactory.js +43 -0
  28. package/dist/runtimes/AdapterFactory.js.map +1 -0
  29. package/dist/runtimes/HttpAdapter.d.ts +23 -0
  30. package/dist/runtimes/HttpAdapter.js +10 -0
  31. package/dist/runtimes/HttpAdapter.js.map +1 -0
  32. package/dist/runtimes/UniversalHttpAdapter.d.ts +19 -0
  33. package/dist/runtimes/UniversalHttpAdapter.js +114 -0
  34. package/dist/runtimes/UniversalHttpAdapter.js.map +1 -0
  35. package/dist/runtimes/detectRuntime.d.ts +34 -0
  36. package/dist/runtimes/detectRuntime.js +77 -0
  37. package/dist/runtimes/detectRuntime.js.map +1 -0
  38. package/dist/types/index.d.ts +5 -0
  39. package/dist/types/index.js +22 -0
  40. package/dist/types/index.js.map +1 -0
  41. package/dist/types/middleware.d.ts +16 -0
  42. package/dist/types/middleware.js +3 -0
  43. package/dist/types/middleware.js.map +1 -0
  44. package/dist/types/plugin.d.ts +43 -0
  45. package/dist/types/plugin.js +3 -0
  46. package/dist/types/plugin.js.map +1 -0
  47. package/dist/types/request.d.ts +5 -0
  48. package/dist/types/response.d.ts +23 -1
  49. package/package.json +24 -5
  50. package/src/adapters/httpAdapter.ts +0 -0
  51. package/src/adapters/index.ts +0 -0
  52. package/src/adapters/xhrAdapter.ts +0 -0
  53. package/src/cache/memoryCache.ts +45 -0
  54. package/src/config/mergeConfig.ts +0 -0
  55. package/src/core/Azios.ts +184 -0
  56. package/src/core/createInstance.ts +23 -0
  57. package/src/core/dispatchRequest.ts +111 -0
  58. package/src/core/requestMethods.ts +0 -0
  59. package/src/core/requestStore.ts +13 -0
  60. package/src/errors/AziosError.ts +26 -0
  61. package/src/helpers/buildURL.ts +44 -0
  62. package/src/helpers/normalizeHeaders.ts +0 -0
  63. package/src/helpers/parseHeaders.ts +0 -0
  64. package/src/index.ts +64 -0
  65. package/src/interceptors/InterceptorManager.ts +30 -0
  66. package/src/middleware/MiddlewarePipeline.ts +155 -0
  67. package/src/middleware/compose.ts +33 -0
  68. package/src/middleware/middlewareManager.ts +9 -0
  69. package/src/plugins/pluginManager.ts +143 -0
  70. package/src/rateLimiter/rateLimiter.ts +36 -0
  71. package/src/runtimes/AdapterFactory.ts +46 -0
  72. package/src/runtimes/HttpAdapter.ts +26 -0
  73. package/src/runtimes/UniversalHttpAdapter.ts +136 -0
  74. package/src/runtimes/detectRuntime.ts +85 -0
  75. package/src/types/config.ts +30 -0
  76. package/src/types/index.ts +5 -0
  77. package/src/types/middleware.ts +21 -0
  78. package/src/types/plugin.ts +50 -0
  79. package/src/types/request.ts +39 -0
  80. package/src/types/response.ts +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Azeem Ali
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,351 +1,176 @@
1
1
  # Aziosxjs
2
2
 
3
- A modern, lightweight HTTP client for Node.js designed for performance, extensibility, and clarity.
3
+ [![npm version](https://badge.fury.io/js/aziosxjs.svg)](https://badge.fury.io/js/aziosxjs) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/) [![Node.js](https://img.shields.io/badge/Node.js-14+-green.svg)](https://nodejs.org/)
4
4
 
5
- Aziosxjs provides a clean API for making HTTP requests while exposing a modular request pipeline architecture.
6
- It is built directly on Node.js low-level `http` and `https` modules to demonstrate how production-grade HTTP clients work internally.
7
-
8
- The goal of this project is to provide a simple but powerful HTTP client that supports advanced features such as retries, caching, request deduplication, and rate limiting.
5
+ A lightweight, modular HTTP client with a clean API and a composable request pipeline.
9
6
 
10
7
  ---
11
8
 
12
- # Features
13
-
14
- ### Core HTTP
15
-
16
- * Promise-based HTTP requests
17
- * Support for GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
18
- * Automatic JSON parsing
19
- * Automatic request body serialization
20
- * Query parameter serialization
21
-
22
- ### Request Pipeline
23
-
24
- * Request interceptors
25
- * Response interceptors
26
- * Structured error system
27
- * AbortController cancellation support
28
-
29
- ### Performance Features
30
-
31
- * Automatic retry system
32
- * Exponential backoff strategy
33
- * Request deduplication (prevents duplicate concurrent requests)
34
- * Response caching
35
- * Built-in rate limiting
36
-
37
- ### Developer Experience
9
+ ## Table of Contents
38
10
 
39
- * TypeScript support
40
- * Modular architecture
41
- * Lightweight dependency-free implementation
11
+ - [Installation](#installation)
12
+ - [Quick Start](#quick-start)
13
+ - [Core Concepts](#core-concepts)
14
+ - [Plugins & Middleware](#plugins--middleware)
15
+ - [Performance Features](#performance-features)
16
+ - [Error Handling](#error-handling)
17
+ - [Running Tests](#running-tests)
18
+ - [Contributing](#contributing)
19
+ - [License](#license)
42
20
 
43
21
  ---
44
22
 
45
- # Installation
23
+ ## Installation
46
24
 
47
- ```bash id="x0c2qz"
25
+ ```bash
48
26
  npm install aziosxjs
49
27
  ```
50
28
 
51
29
  ---
52
30
 
53
- # Quick Example
31
+ ## Quick Start
54
32
 
55
- ```javascript id="xgqz2e"
33
+ ```js
56
34
  import azios from "aziosxjs";
57
35
 
58
- async function getUsers() {
59
- const response = await azios.get(
60
- "https://jsonplaceholder.typicode.com/users"
61
- );
62
-
63
- console.log(response.data);
64
- }
65
-
66
- getUsers();
36
+ const response = await azios.get("https://jsonplaceholder.typicode.com/users/1");
37
+ console.log(response.data);
67
38
  ```
68
39
 
69
40
  ---
70
41
 
71
- # Basic Usage
72
-
73
- ## GET Request
42
+ ## Core Concepts
74
43
 
75
- ```javascript id="q2s48a"
76
- const res = await azios.get("https://api.example.com/users");
44
+ ### HTTP Methods
77
45
 
78
- console.log(res.data);
46
+ ```js
47
+ await azios.get("/users");
48
+ await azios.post("/users", { name: "Jane" });
49
+ await azios.put("/users/1", { name: "Jane" });
50
+ await azios.delete("/users/1");
79
51
  ```
80
52
 
81
- ---
82
-
83
- ## POST Request
53
+ ### Configuration
84
54
 
85
- ```javascript id="ys8fr0"
86
- const res = await azios.post(
87
- "https://api.example.com/login",
88
- {
89
- username: "user",
90
- password: "password"
91
- }
92
- );
93
-
94
- console.log(res.data);
55
+ ```js
56
+ const response = await azios.request({
57
+ url: "/users",
58
+ method: "GET",
59
+ baseURL: "https://api.example.com",
60
+ params: { page: 1, limit: 10 },
61
+ headers: { Authorization: "Bearer TOKEN" },
62
+ timeout: 5000,
63
+ });
95
64
  ```
96
65
 
97
- ---
98
-
99
- # Query Parameters
100
-
101
- Aziosxjs automatically serializes query parameters.
102
-
103
- ```javascript id="6e6w1q"
104
- const res = await azios.get(
105
- "https://jsonplaceholder.typicode.com/posts",
106
- {
107
- params: { _limit: 2 }
108
- }
109
- );
66
+ ### Instances
110
67
 
111
- console.log(res.data);
112
- ```
113
-
114
- Generated URL:
68
+ ```js
69
+ import { createInstance } from "aziosxjs";
115
70
 
116
- ```id="2dq3rc"
117
- /posts?_limit=2
71
+ const api = createInstance({ baseURL: "https://api.example.com" });
72
+ await api.get("/users");
118
73
  ```
119
74
 
120
75
  ---
121
76
 
122
- # Interceptors
123
-
124
- Interceptors allow you to modify requests or responses globally.
125
-
126
- ## Request Interceptor
77
+ ## Plugins & Middleware
127
78
 
128
- ```javascript id="o7j8rz"
129
- azios.interceptors.request.use(config => {
130
- console.log("Request intercepted");
79
+ ### Plugin System
131
80
 
132
- if (!config.headers) config.headers = {};
133
- config.headers["x-client"] = "aziosxjs";
81
+ Plugins provide a clean way to extend Aziosxjs behavior.
134
82
 
135
- return config;
136
- });
137
- ```
138
-
139
- ---
83
+ ```js
84
+ import type { AziosPlugin } from "aziosxjs";
140
85
 
141
- ## Response Interceptor
86
+ const authPlugin: AziosPlugin = {
87
+ name: "auth",
88
+ version: "1.0.0",
89
+ hooks: {
90
+ beforeRequest: (config) => ({
91
+ ...config,
92
+ headers: { ...config.headers, Authorization: "Bearer TOKEN" },
93
+ }),
94
+ },
95
+ };
142
96
 
143
- ```javascript id="w7r0uj"
144
- azios.interceptors.response.use(response => {
145
- console.log("Response intercepted");
146
- return response;
147
- });
97
+ await azios.installPlugin(authPlugin);
148
98
  ```
149
99
 
150
- ---
151
-
152
- # Request Cancellation
100
+ ### Middleware
153
101
 
154
- Requests can be cancelled using `AbortController`.
102
+ Middleware runs in sequence and can modify the request/response pipeline.
155
103
 
156
- ```javascript id="68f4s3"
157
- const controller = new AbortController();
104
+ ```js
105
+ import type { AziosMiddleware } from "aziosxjs";
158
106
 
159
- azios.get(
160
- "https://jsonplaceholder.typicode.com/users",
161
- { signal: controller.signal }
162
- );
107
+ const logger: AziosMiddleware = async (config, next) => {
108
+ console.log("→", config.method, config.url);
109
+ const res = await next();
110
+ console.log("←", res.status);
111
+ return res;
112
+ };
163
113
 
164
- controller.abort();
165
- ```
166
-
167
- If aborted, Aziosxjs throws an error with code:
168
-
169
- ```id="m5ktg3"
170
- ABORTED
114
+ azios.use(logger);
171
115
  ```
172
116
 
173
117
  ---
174
118
 
175
- # Retry System
119
+ ## Performance Features
176
120
 
177
- Aziosxjs can automatically retry failed requests.
121
+ ### Retry + Backoff
178
122
 
179
- ```javascript id="zwdg7p"
180
- await azios.get("https://api.example.com/users", {
181
- retry: 3
182
- });
123
+ ```js
124
+ await azios.get("/unstable", { retry: 3, retryDelay: 500 });
183
125
  ```
184
126
 
185
- Retries use **exponential backoff** to avoid overwhelming servers.
186
-
187
- ---
127
+ ### Deduplication
188
128
 
189
- # Response Caching
129
+ Identical concurrent requests share the same network call.
190
130
 
191
- Responses can be cached in memory.
131
+ ### Caching
192
132
 
193
- ```javascript id="hjbrgx"
194
- await azios.get(
195
- "https://api.example.com/users",
196
- { cache: true }
197
- );
133
+ ```js
134
+ await azios.get("/users", { cache: true, cacheTTL: 5000 });
198
135
  ```
199
136
 
200
- Subsequent requests may return cached responses instantly.
201
-
202
- ---
203
-
204
- # Rate Limiting
137
+ ### Rate Limiting
205
138
 
206
- Control the number of concurrent requests.
207
-
208
- ```javascript id="m2l4x9"
209
- await azios.get(
210
- "https://api.example.com/users",
211
- { rateLimit: 3 }
212
- );
139
+ ```js
140
+ await azios.get("/users", { rateLimit: 5 });
213
141
  ```
214
142
 
215
- Only 3 requests will execute simultaneously.
216
-
217
143
  ---
218
144
 
219
- # Error Handling
145
+ ## Error Handling
220
146
 
221
- Aziosxjs returns standardized error objects.
147
+ Aziosxjs throws `AziosError` instances with structured metadata.
222
148
 
223
- ```javascript id="n2d3kr"
149
+ ```js
224
150
  try {
225
- await azios.get("https://invalid-url.test");
226
- } catch (error) {
227
- console.log(error.name); // AziosError
228
- console.log(error.code); // NETWORK_ERROR
151
+ await azios.get("/404");
152
+ } catch (err) {
153
+ console.log(err.code, err.message);
229
154
  }
230
155
  ```
231
156
 
232
- This makes debugging significantly easier.
233
-
234
157
  ---
235
158
 
236
- # Request Pipeline Architecture
237
-
238
- Aziosxjs follows a modular pipeline design.
239
-
240
- ```id="m2b3ux"
241
- User Code
242
-
243
- Azios Instance
244
-
245
- Request Interceptors
246
-
247
- Retry Engine
248
-
249
- Rate Limiter
250
-
251
- dispatchRequest (HTTP engine)
252
-
253
- Node.js http / https
254
-
255
- Response Interceptors
256
-
257
- Return Response
258
- ```
259
-
260
- ---
159
+ ## Running Tests
261
160
 
262
- # Project Structure
263
-
264
- ```id="v2z3go"
265
- src
266
- ├── core
267
- │ ├── Azios.ts
268
- │ ├── createInstance.ts
269
- │ ├── dispatchRequest.ts
270
- │ └── requestStore.ts
271
-
272
- ├── cache
273
- │ └── memoryCache.ts
274
-
275
- ├── rateLimiter
276
- │ └── rateLimiter.ts
277
-
278
- ├── interceptors
279
- │ └── InterceptorManager.ts
280
-
281
- ├── errors
282
- │ └── AziosError.ts
283
-
284
- ├── helpers
285
- │ └── buildURL.ts
286
-
287
- ├── types
288
- │ ├── config.ts
289
- │ ├── request.ts
290
- │ └── response.ts
291
-
292
- └── index.ts
161
+ ```bash
162
+ npm test
293
163
  ```
294
164
 
295
165
  ---
296
166
 
297
- # Version Roadmap
298
-
299
- ### v0.1
300
-
301
- * Core HTTP client
302
- * Instances
303
- * JSON handling
304
- * Request configuration
167
+ ## Contributing
305
168
 
306
- ### v0.2
307
-
308
- * Interceptor pipeline
309
- * Structured error system
310
- * Request cancellation
311
- * Query parameter serialization
312
-
313
- ### v0.3
314
-
315
- * Retry mechanism
316
- * Exponential backoff
317
- * Request deduplication
318
-
319
- ### v0.4
320
-
321
- * Response caching
322
- * Rate limiting
323
-
324
- ### Planned
325
-
326
- * Plugin system
327
- * Middleware pipeline
328
- * Advanced TypeScript inference
329
- * Universal runtime support (Node, Browser, Edge)
169
+ Contributions are welcome. Please open an issue or pull request.
330
170
 
331
171
  ---
332
172
 
333
- # Contributing
334
-
335
- Contributions are welcome.
336
-
337
- 1. Fork the repository
338
- 2. Create a feature branch
339
- 3. Submit a pull request
340
-
341
- ---
342
-
343
- # Author
344
-
345
- Azeem Ali
346
-
347
- ---
173
+ ## License
348
174
 
349
- # License
175
+ MIT © 2026 Azeem Ali
350
176
 
351
- MIT
@@ -1,3 +1,4 @@
1
1
  export declare function getCache(key: string): any;
2
2
  export declare function setCache(key: string, value: any, ttl?: number): void;
3
3
  export declare function clearCache(key: string): void;
4
+ export declare function clearAllCache(): void;
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCache = getCache;
4
4
  exports.setCache = setCache;
5
5
  exports.clearCache = clearCache;
6
+ exports.clearAllCache = clearAllCache;
6
7
  const cache = new Map();
7
8
  function getCache(key) {
8
9
  const entry = cache.get(key);
9
10
  if (!entry)
10
11
  return null;
12
+ // remove expired cache
11
13
  if (Date.now() > entry.expiry) {
12
14
  cache.delete(key);
13
15
  return null;
@@ -15,12 +17,16 @@ function getCache(key) {
15
17
  return entry.data;
16
18
  }
17
19
  function setCache(key, value, ttl = 5000) {
20
+ const expiry = Date.now() + ttl;
18
21
  cache.set(key, {
19
22
  data: value,
20
- expiry: Date.now() + ttl
23
+ expiry
21
24
  });
22
25
  }
23
26
  function clearCache(key) {
24
27
  cache.delete(key);
25
28
  }
29
+ function clearAllCache() {
30
+ cache.clear();
31
+ }
26
32
  //# sourceMappingURL=memoryCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memoryCache.js","sourceRoot":"","sources":["../../src/cache/memoryCache.ts"],"names":[],"mappings":";;AAEA,4BAaC;AAED,4BAOC;AAED,gCAEC;AA5BD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyC,CAAA;AAE9D,SAAgB,QAAQ,CAAC,GAAW;IAElC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAE5B,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IAEvB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAA;AAEnB,CAAC;AAED,SAAgB,QAAQ,CAAC,GAAW,EAAE,KAAU,EAAE,GAAG,GAAG,IAAI;IAE1D,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;QACb,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG;KACzB,CAAC,CAAA;AAEJ,CAAC;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC"}
1
+ {"version":3,"file":"memoryCache.js","sourceRoot":"","sources":["../../src/cache/memoryCache.ts"],"names":[],"mappings":";;AAOA,4BAcC;AAED,4BAaC;AAED,gCAEC;AAED,sCAEC;AAvCD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE3C,SAAgB,QAAQ,CAAC,GAAW;IAElC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAE5B,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IAEvB,uBAAuB;IACvB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAA;AAEnB,CAAC;AAED,SAAgB,QAAQ,CACtB,GAAW,EACX,KAAU,EACV,MAAc,IAAI;IAGlB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAA;IAE/B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;QACb,IAAI,EAAE,KAAK;QACX,MAAM;KACP,CAAC,CAAA;AAEJ,CAAC;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC;AAED,SAAgB,aAAa;IAC3B,KAAK,CAAC,KAAK,EAAE,CAAA;AACf,CAAC"}
@@ -1,18 +1,43 @@
1
1
  import { AziosRequestConfig } from "../types/config";
2
+ import type { AziosPlugin } from "../types/plugin";
2
3
  import InterceptorManager from "../interceptors/InterceptorManager";
4
+ import PluginManager from "../plugins/pluginManager";
5
+ import MiddlewareManager from "../middleware/middlewareManager";
6
+ /**
7
+ * Core Azios HTTP client class
8
+ * Production-grade implementation with plugin system, middleware, and interceptors
9
+ */
3
10
  export default class Azios {
4
11
  defaults: AziosRequestConfig;
5
12
  interceptors: {
6
13
  request: InterceptorManager<AziosRequestConfig>;
7
14
  response: InterceptorManager<any>;
8
15
  };
16
+ middlewares: MiddlewareManager;
17
+ plugins: PluginManager;
9
18
  constructor(config: AziosRequestConfig);
10
- request(config: AziosRequestConfig): Promise<AziosRequestConfig>;
11
- get(url: string, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
12
- post(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
13
- put(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
14
- patch(url: string, data?: any, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
15
- delete(url: string, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
16
- head(url: string, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
17
- options(url: string, config?: AziosRequestConfig): Promise<AziosRequestConfig>;
19
+ /**
20
+ * Register middleware using Koa-style middleware pattern
21
+ */
22
+ use(fn: any): void;
23
+ /**
24
+ * Install a plugin into this instance
25
+ * @throws Error if plugin is already installed or installation fails
26
+ */
27
+ installPlugin(plugin: AziosPlugin): Promise<void>;
28
+ /**
29
+ * Uninstall a plugin by name
30
+ */
31
+ uninstallPlugin(pluginName: string): Promise<void>;
32
+ /**
33
+ * Core request method - central request pipeline
34
+ */
35
+ request(config: AziosRequestConfig): Promise<any>;
36
+ get(url: string, config?: AziosRequestConfig): Promise<any>;
37
+ post(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
38
+ put(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
39
+ patch(url: string, data?: any, config?: AziosRequestConfig): Promise<any>;
40
+ delete(url: string, config?: AziosRequestConfig): Promise<any>;
41
+ head(url: string, config?: AziosRequestConfig): Promise<any>;
42
+ options(url: string, config?: AziosRequestConfig): Promise<any>;
18
43
  }
@@ -5,6 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const dispatchRequest_1 = __importDefault(require("./dispatchRequest"));
7
7
  const InterceptorManager_1 = __importDefault(require("../interceptors/InterceptorManager"));
8
+ const pluginManager_1 = __importDefault(require("../plugins/pluginManager"));
9
+ const middlewareManager_1 = __importDefault(require("../middleware/middlewareManager"));
10
+ const compose_1 = require("../middleware/compose");
11
+ /**
12
+ * Core Azios HTTP client class
13
+ * Production-grade implementation with plugin system, middleware, and interceptors
14
+ */
8
15
  class Azios {
9
16
  constructor(config) {
10
17
  this.defaults = config;
@@ -12,14 +19,55 @@ class Azios {
12
19
  request: new InterceptorManager_1.default(),
13
20
  response: new InterceptorManager_1.default()
14
21
  };
22
+ this.middlewares = new middlewareManager_1.default();
23
+ this.plugins = new pluginManager_1.default();
15
24
  }
16
- request(config) {
25
+ /**
26
+ * Register middleware using Koa-style middleware pattern
27
+ */
28
+ use(fn) {
29
+ this.middlewares.use(fn);
30
+ }
31
+ /**
32
+ * Install a plugin into this instance
33
+ * @throws Error if plugin is already installed or installation fails
34
+ */
35
+ async installPlugin(plugin) {
36
+ await this.plugins.install(plugin, this);
37
+ }
38
+ /**
39
+ * Uninstall a plugin by name
40
+ */
41
+ async uninstallPlugin(pluginName) {
42
+ await this.plugins.uninstall(pluginName, this);
43
+ }
44
+ /**
45
+ * Core request method - central request pipeline
46
+ */
47
+ async request(config) {
17
48
  config = { ...this.defaults, ...config };
49
+ // -------------------------
50
+ // PLUGIN: PRE-REQUEST HOOKS
51
+ // -------------------------
52
+ config = await this.plugins.executeBeforeRequestHooks(config);
53
+ // -------------------------
54
+ // MIDDLEWARE PIPELINE
55
+ // -------------------------
56
+ const context = { config };
57
+ const fn = (0, compose_1.compose)(this.middlewares.middlewares);
58
+ await fn(context);
59
+ config = context.config;
60
+ // -------------------------
61
+ // INTERCEPTOR PIPELINE
62
+ // -------------------------
18
63
  const chain = [];
64
+ // Request interceptors (reverse order)
19
65
  this.interceptors.request.forEach(interceptor => {
20
66
  chain.unshift(interceptor.fulfilled, interceptor.rejected);
21
67
  });
68
+ // Main dispatch
22
69
  chain.push(dispatchRequest_1.default, undefined);
70
+ // Response interceptors (normal order)
23
71
  this.interceptors.response.forEach(interceptor => {
24
72
  chain.push(interceptor.fulfilled, interceptor.rejected);
25
73
  });
@@ -29,8 +77,26 @@ class Azios {
29
77
  const rejected = chain.shift();
30
78
  promise = promise.then(fulfilled, rejected);
31
79
  }
32
- return promise;
80
+ try {
81
+ const response = await promise;
82
+ // -------------------------
83
+ // PLUGIN: POST-RESPONSE HOOKS
84
+ // -------------------------
85
+ return await this.plugins.executeAfterResponseHooks(response);
86
+ }
87
+ catch (error) {
88
+ // -------------------------
89
+ // PLUGIN: ERROR HOOKS
90
+ // -------------------------
91
+ if (error instanceof Error) {
92
+ throw await this.plugins.executeOnErrorHooks(error);
93
+ }
94
+ throw error;
95
+ }
33
96
  }
97
+ // =========================================
98
+ // HTTP METHODS
99
+ // =========================================
34
100
  get(url, config) {
35
101
  return this.request({
36
102
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"Azios.js","sourceRoot":"","sources":["../../src/core/Azios.ts"],"names":[],"mappings":";;;;;AAAA,wEAA+C;AAE/C,4FAAmE;AAEnE,MAAqB,KAAK;IASxB,YAAY,MAA0B;QAEpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAA;QAEtB,IAAI,CAAC,YAAY,GAAG;YAClB,OAAO,EAAE,IAAI,4BAAkB,EAAE;YACjC,QAAQ,EAAE,IAAI,4BAAkB,EAAE;SACnC,CAAA;IACH,CAAC;IAED,OAAO,CAAC,MAA0B;QAEhC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAA;QAExC,MAAM,KAAK,GAAU,EAAE,CAAA;QAEvB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC9C,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,IAAI,CAAC,yBAAe,EAA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