aziosxjs 1.0.0 โ†’ 1.0.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.
package/README.md CHANGED
@@ -1,176 +1,476 @@
1
1
  # Aziosxjs
2
2
 
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/)
3
+ [![npm version](https://img.shields.io/npm/v/aziosxjs?style=flat-square)](https://www.npmjs.com/package/aziosxjs)
4
+ [![npm downloads](https://img.shields.io/npm/dm/aziosxjs?style=flat-square)](https://www.npmjs.com/package/aziosxjs)
5
+ [![npm downloads per week](https://img.shields.io/npm/dw/aziosxjs?style=flat-square)](https://www.npmjs.com/package/aziosxjs)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg?style=flat-square)](https://www.typescriptlang.org/)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-14+-green.svg?style=flat-square)](https://nodejs.org/)
9
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](CONTRIBUTING.md)
4
10
 
5
- A lightweight, modular HTTP client with a clean API and a composable request pipeline.
11
+ > ๐Ÿš€ **Advanced HTTP client with request monitoring, built-in auth, plugins, middleware, and universal runtime support**
6
12
 
7
- ---
13
+ **Aziosxjs** is a modern, lightweight, and highly extensible HTTP client for JavaScript/TypeScript applications. Built for production, featuring intelligent request monitoring, native authentication management, and a powerful plugin architecture.
8
14
 
9
- ## Table of Contents
15
+ ---
10
16
 
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)
17
+ ## ๐ŸŒŸ Why Aziosxjs?
18
+
19
+ | Feature | Aziosxjs | Axios | Fetch |
20
+ |---------|----------|-------|-------|
21
+ | **Request Monitoring** | โœ… Built-in dashboard | โŒ 3rd party | โŒ No |
22
+ | **Auth Manager** | โœ… Native + auto-refresh | โŒ Manual | โŒ No |
23
+ | **Plugin System** | โœ… Full lifecycle | โŒ No | โŒ No |
24
+ | **Middleware** | โœ… Koa-style | โŒ No | โŒ No |
25
+ | **Interceptors** | โœ… Request/Response | โœ… Yes | โŒ No |
26
+ | **Retry Logic** | โœ… Exponential backoff | โŒ No | โŒ No |
27
+ | **Caching** | โœ… TTL-based | โŒ No | โŒ No |
28
+ | **Rate Limiting** | โœ… Built-in | โŒ No | โŒ No |
29
+ | **TypeScript** | โœ… Full support | โœ… Yes | โœ… Partial |
30
+ | **Universal Runtime** | โœ… Node/Browser/Deno | โŒ Node/Browser | โœ… Universal |
20
31
 
21
32
  ---
22
33
 
23
- ## Installation
34
+ ## ๐Ÿš€ Quick Start
35
+
36
+ ### Installation
24
37
 
25
38
  ```bash
26
39
  npm install aziosxjs
27
40
  ```
28
41
 
29
- ---
42
+ ### Basic Usage
43
+
44
+ ```typescript
45
+ import azios from 'aziosxjs'
46
+
47
+ // GET request
48
+ const user = await azios.get('https://api.example.com/users/1')
49
+ console.log(user.data)
30
50
 
31
- ## Quick Start
51
+ // POST request
52
+ const post = await azios.post('https://api.example.com/posts', {
53
+ title: 'Hello World',
54
+ body: 'My first post'
55
+ })
32
56
 
33
- ```js
34
- import azios from "aziosxjs";
57
+ // PUT request
58
+ await azios.put('https://api.example.com/posts/1', {
59
+ title: 'Updated Title'
60
+ })
35
61
 
36
- const response = await azios.get("https://jsonplaceholder.typicode.com/users/1");
37
- console.log(response.data);
62
+ // DELETE request
63
+ await azios.delete('https://api.example.com/posts/1')
38
64
  ```
39
65
 
40
66
  ---
41
67
 
42
- ## Core Concepts
68
+ ## โœจ Key Features
69
+
70
+ ### 1. ๐Ÿ“Š Request Monitoring & Debug Dashboard
71
+
72
+ Monitor all HTTP requests with real-time debugging:
73
+
74
+ ```typescript
75
+ import azios from 'aziosxjs'
76
+
77
+ // Enable monitoring
78
+ azios.monitor.enable()
79
+
80
+ // Make requests...
81
+ await azios.get('https://api.example.com/users')
43
82
 
44
- ### HTTP Methods
83
+ // View request history
84
+ console.log(azios.monitor.getHistory())
45
85
 
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");
86
+ // Get statistics
87
+ console.log(azios.monitor.getStats())
88
+ // { totalRequests: 5, totalErrors: 1, averageDuration: 245, ... }
89
+
90
+ // Export for analysis
91
+ const json = azios.monitor.exportJSON()
92
+ const csv = azios.monitor.exportCSV()
93
+
94
+ // Filter and analyze
95
+ const errors = azios.monitor.getErrors()
96
+ const getRequests = azios.monitor.getByMethod('GET')
51
97
  ```
52
98
 
53
- ### Configuration
99
+ ### 2. ๐Ÿ” Built-in Authentication Manager
54
100
 
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
- });
101
+ Enterprise-grade authentication with automatic token refresh:
102
+
103
+ ```typescript
104
+ import azios, { createAuthPlugin } from 'aziosxjs'
105
+
106
+ // Setup auth
107
+ const authPlugin = createAuthPlugin({
108
+ refreshUrl: 'https://api.example.com/auth/refresh',
109
+ logoutUrl: 'https://api.example.com/auth/logout'
110
+ })
111
+
112
+ await azios.installPlugin(authPlugin)
113
+
114
+ // Now all requests:
115
+ // โœ… Attach Authorization headers
116
+ // โœ… Detect 401 responses
117
+ // โœ… Refresh token automatically
118
+ // โœ… Retry with new token
64
119
  ```
65
120
 
66
- ### Instances
121
+ ### 3. ๐Ÿ”Œ Plugin System
67
122
 
68
- ```js
69
- import { createInstance } from "aziosxjs";
123
+ Extend functionality with a clean plugin architecture:
70
124
 
71
- const api = createInstance({ baseURL: "https://api.example.com" });
72
- await api.get("/users");
125
+ ```typescript
126
+ import azios, { AziosPlugin } from 'aziosxjs'
127
+
128
+ const loggingPlugin: AziosPlugin = {
129
+ name: 'logger',
130
+ version: '1.0.0',
131
+ hooks: {
132
+ beforeRequest: (config) => {
133
+ console.log(`๐Ÿ“ก ${config.method} ${config.url}`)
134
+ return config
135
+ },
136
+ afterResponse: (response) => {
137
+ console.log(`โœ… Status: ${response.status}`)
138
+ return response
139
+ }
140
+ }
141
+ }
142
+
143
+ await azios.installPlugin(loggingPlugin)
144
+ ```
145
+
146
+ ### 4. โš™๏ธ Middleware Pipeline
147
+
148
+ Koa-style middleware for request processing:
149
+
150
+ ```typescript
151
+ azios.use(async (ctx, next) => {
152
+ console.log('Before request')
153
+ await next()
154
+ console.log('After response')
155
+ })
156
+ ```
157
+
158
+ ### 5. ๐Ÿ”„ Interceptors
159
+
160
+ Intercept and transform requests/responses:
161
+
162
+ ```typescript
163
+ azios.interceptors.request.use(
164
+ (config) => {
165
+ config.headers.Authorization = `Bearer ${token}`
166
+ return config
167
+ }
168
+ )
169
+
170
+ azios.interceptors.response.use(
171
+ (response) => response,
172
+ (error) => {
173
+ if (error.response?.status === 401) {
174
+ // Handle unauthorized
175
+ }
176
+ return Promise.reject(error)
177
+ }
178
+ )
179
+ ```
180
+
181
+ ### 6. โšก Performance Features
182
+
183
+ #### Retry with Exponential Backoff
184
+ ```typescript
185
+ await azios.get('/api/data', {
186
+ retry: 3, // Retry 3 times
187
+ retryDelay: 1000 // 1s, 2s, 4s delays
188
+ })
189
+ ```
190
+
191
+ #### Response Caching
192
+ ```typescript
193
+ await azios.get('/api/users', {
194
+ cache: true, // Enable caching
195
+ cacheTTL: 60000 // Cache for 60 seconds
196
+ })
197
+ ```
198
+
199
+ #### Rate Limiting
200
+ ```typescript
201
+ await azios.post('/api/data', payload, {
202
+ rateLimit: 1000 // 1 request per second
203
+ })
204
+ ```
205
+
206
+ #### Request Deduplication
207
+ ```typescript
208
+ // Both use the same network call
209
+ const [data1, data2] = await Promise.all([
210
+ azios.get('/api/users/1'),
211
+ azios.get('/api/users/1')
212
+ ])
73
213
  ```
74
214
 
75
215
  ---
76
216
 
77
- ## Plugins & Middleware
217
+ ## ๐Ÿ“– Complete Examples
78
218
 
79
- ### Plugin System
219
+ ### Example 1: Simple GET/POST
80
220
 
81
- Plugins provide a clean way to extend Aziosxjs behavior.
221
+ ```typescript
222
+ import azios from 'aziosxjs'
82
223
 
83
- ```js
84
- import type { AziosPlugin } from "aziosxjs";
224
+ async function main() {
225
+ const users = await azios.get('https://jsonplaceholder.typicode.com/users')
226
+ console.log(users.data)
85
227
 
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
- };
228
+ const post = await azios.post('https://jsonplaceholder.typicode.com/posts', {
229
+ title: 'My Post',
230
+ body: 'Content',
231
+ userId: 1
232
+ })
233
+ console.log(post.data)
234
+ }
235
+ ```
236
+
237
+ ### Example 2: With Request Monitoring
96
238
 
97
- await azios.installPlugin(authPlugin);
239
+ ```typescript
240
+ azios.monitor.enable()
241
+
242
+ await azios.get('https://api.example.com/users')
243
+ await azios.post('https://api.example.com/data', { /* data */ })
244
+
245
+ console.log(azios.monitor.getSummary())
246
+ console.log(azios.monitor.getStats())
98
247
  ```
99
248
 
100
- ### Middleware
249
+ ### Example 3: With Authentication
250
+
251
+ ```typescript
252
+ const authPlugin = createAuthPlugin({
253
+ refreshUrl: 'https://api.example.com/refresh',
254
+ logoutUrl: 'https://api.example.com/logout'
255
+ })
256
+
257
+ await azios.installPlugin(authPlugin)
258
+
259
+ // Requests automatically handle auth and token refresh
260
+ const data = await azios.get('https://api.example.com/protected')
261
+ ```
101
262
 
102
- Middleware runs in sequence and can modify the request/response pipeline.
263
+ ### Example 4: Custom Instances
103
264
 
104
- ```js
105
- import type { AziosMiddleware } from "aziosxjs";
265
+ ```typescript
266
+ import { createInstance } from 'aziosxjs'
106
267
 
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
- };
268
+ const api = createInstance({
269
+ baseURL: 'https://api.example.com',
270
+ timeout: 10000,
271
+ headers: {
272
+ 'X-Custom-Header': 'value'
273
+ }
274
+ })
113
275
 
114
- azios.use(logger);
276
+ const data = await api.get('/users')
277
+ ```
278
+
279
+ ### Example 5: Advanced Configuration
280
+
281
+ ```typescript
282
+ const response = await azios.request({
283
+ url: '/api/users',
284
+ method: 'GET',
285
+ baseURL: 'https://api.example.com',
286
+ headers: { Authorization: 'Bearer token' },
287
+ params: { page: 1, limit: 10 },
288
+ timeout: 5000,
289
+ retry: 2,
290
+ retryDelay: 500,
291
+ cache: true,
292
+ cacheTTL: 30000,
293
+ rateLimit: 1000
294
+ })
295
+ ```
296
+
297
+ ---
298
+
299
+ ## ๐Ÿ”ง Configuration
300
+
301
+ ### Request Config API
302
+
303
+ ```typescript
304
+ interface AziosRequestConfig {
305
+ url?: string
306
+ method?: string
307
+ baseURL?: string
308
+ headers?: Record<string, any>
309
+ params?: Record<string, any>
310
+ data?: any
311
+ timeout?: number
312
+ responseType?: string
313
+ signal?: AbortSignal
314
+ retry?: number
315
+ retryDelay?: number
316
+ cache?: boolean
317
+ cacheTTL?: number
318
+ rateLimit?: number
319
+ }
115
320
  ```
116
321
 
117
322
  ---
118
323
 
119
- ## Performance Features
324
+ ## ๐Ÿ“ฆ TypeScript Support
325
+
326
+ Full TypeScript support with complete type safety:
120
327
 
121
- ### Retry + Backoff
328
+ ```typescript
329
+ import azios, {
330
+ AziosInstance,
331
+ AziosRequestConfig,
332
+ AziosResponse,
333
+ RequestLog,
334
+ TokenConfig
335
+ } from 'aziosxjs'
122
336
 
123
- ```js
124
- await azios.get("/unstable", { retry: 3, retryDelay: 500 });
337
+ const response: AziosResponse = await azios.get('/api/users')
125
338
  ```
126
339
 
127
- ### Deduplication
340
+ ---
128
341
 
129
- Identical concurrent requests share the same network call.
342
+ ## ๐ŸŒ Universal Runtime Support
130
343
 
131
- ### Caching
344
+ Works across different JavaScript runtimes:
132
345
 
133
- ```js
134
- await azios.get("/users", { cache: true, cacheTTL: 5000 });
346
+ ```typescript
347
+ import { detectRuntime, currentRuntime } from 'aziosxjs'
348
+
349
+ console.log(currentRuntime) // 'node' | 'browser' | 'deno' | 'bun'
135
350
  ```
136
351
 
137
- ### Rate Limiting
352
+ Supported: Node.js, Browser, Deno, Bun
353
+
354
+ ---
355
+
356
+ ## ๐ŸŽฏ API Reference
357
+
358
+ ### Monitoring API
359
+
360
+ ```typescript
361
+ azios.monitor.enable() // Enable tracking
362
+ azios.monitor.disable() // Disable tracking
363
+ azios.monitor.getHistory() // Get all logs
364
+ azios.monitor.getStats() // Get statistics
365
+ azios.monitor.getErrors() // Get failed requests
366
+ azios.monitor.getByMethod(method) // Filter by HTTP method
367
+ azios.monitor.getByUrl(pattern) // Filter by URL
368
+ azios.monitor.exportJSON() // Export as JSON
369
+ azios.monitor.exportCSV() // Export as CSV
370
+ azios.monitor.getSummary() // Get formatted summary
371
+ azios.monitor.clear() // Clear all logs
372
+ ```
138
373
 
139
- ```js
140
- await azios.get("/users", { rateLimit: 5 });
374
+ ### Auth Manager API
375
+
376
+ ```typescript
377
+ const auth = new AuthManager()
378
+
379
+ auth.initialize(endpoints) // Setup endpoints
380
+ auth.setToken(token) // Store token
381
+ auth.getToken() // Get stored token
382
+ auth.getAccessToken() // Get access token string
383
+ auth.hasToken() // Check if token exists
384
+ auth.isTokenExpired() // Check expiration
385
+ auth.refreshAccessToken() // Refresh token
386
+ auth.attachAuthHeader(config) // Add auth header
387
+ auth.handle401(config) // Handle 401 response
388
+ auth.logout() // Logout and clear
389
+ auth.getStatus() // Get auth status
141
390
  ```
142
391
 
143
392
  ---
144
393
 
145
- ## Error Handling
394
+ ## ๐Ÿ›ก๏ธ Best Practices
146
395
 
147
- Aziosxjs throws `AziosError` instances with structured metadata.
396
+ ### Security
397
+
398
+ ```typescript
399
+ // โœ… DO: Use secure token storage
400
+ const authPlugin = createAuthPlugin({
401
+ refreshUrl: 'https://api.example.com/auth/refresh',
402
+ logoutUrl: 'https://api.example.com/auth/logout'
403
+ })
404
+
405
+ // โŒ DON'T: Store tokens in localStorage
406
+ // localStorage.setItem('token', sensitiveToken)
407
+ ```
408
+
409
+ ### Error Handling
410
+
411
+ ```typescript
412
+ import { AziosError } from 'aziosxjs'
148
413
 
149
- ```js
150
414
  try {
151
- await azios.get("/404");
152
- } catch (err) {
153
- console.log(err.code, err.message);
415
+ await azios.get('/api/users')
416
+ } catch (error) {
417
+ if (error instanceof AziosError) {
418
+ console.log(`[${error.response?.status}] ${error.message}`)
419
+ }
154
420
  }
155
421
  ```
156
422
 
423
+ ### Production Monitoring
424
+
425
+ ```typescript
426
+ if (process.env.NODE_ENV === 'development') {
427
+ azios.monitor.enable()
428
+ }
429
+
430
+ setInterval(() => {
431
+ const stats = azios.monitor.getStats()
432
+ if (stats.totalErrors > 10) {
433
+ alerting.warn('High error rate!')
434
+ }
435
+ }, 60000)
436
+ ```
437
+
157
438
  ---
158
439
 
159
- ## Running Tests
440
+ ## ๐Ÿงช Testing
160
441
 
161
442
  ```bash
162
- npm test
443
+ npm test # Run all tests
444
+ npm run test:sprint8:monitoring # Test monitoring
445
+ npm run test:sprint8:auth # Test auth
163
446
  ```
164
447
 
165
448
  ---
166
449
 
167
- ## Contributing
450
+ ## ๐Ÿ“š Documentation
451
+
452
+ - [Full Documentation](./docs/)
453
+ - [Examples](./examples/)
454
+ - [Changelog](./CHANGELOG.md)
455
+
456
+ ---
457
+
458
+ ## ๐Ÿค Contributing
459
+
460
+ Contributions welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md)
461
+
462
+ ---
463
+
464
+ ## ๐Ÿ“„ License
168
465
 
169
- Contributions are welcome. Please open an issue or pull request.
466
+ MIT ยฉ 2024 [Azeem Ali](https://github.com/azeemali2001)
170
467
 
171
468
  ---
172
469
 
173
- ## License
470
+ ## ๐Ÿ™‹ Support
174
471
 
175
- MIT ยฉ 2026 Azeem Ali
472
+ - ๐Ÿ“– [Documentation](https://github.com/azeemali2001/azios)
473
+ - ๐Ÿ› [Report Issues](https://github.com/azeemali2001/azios/issues)
474
+ - ๐Ÿ’ฌ [Discussions](https://github.com/azeemali2001/azios/discussions)
176
475
 
476
+ **Made with โค๏ธ for the JavaScript community**
@@ -0,0 +1,18 @@
1
+ import type { AziosRequestConfig } from '../types/config';
2
+ import type { AziosResponse } from '../types/response';
3
+ import { BaseAdapter } from '../runtimes/HttpAdapter';
4
+ /**
5
+ * Node.js HTTP adapter using built-in http/https modules
6
+ * Compatible with Node.js 16+ (before global fetch was available)
7
+ */
8
+ export declare class NodeHttpAdapter extends BaseAdapter {
9
+ /**
10
+ * Check if this adapter is supported (Node.js environment)
11
+ */
12
+ isSupported(): boolean;
13
+ /**
14
+ * Execute HTTP request using Node.js http/https modules
15
+ */
16
+ request(config: AziosRequestConfig): Promise<AziosResponse>;
17
+ }
18
+ export default NodeHttpAdapter;