auravia-connect 1.0.2 β 1.0.3
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 +270 -15
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -1,28 +1,283 @@
|
|
|
1
1
|
# auravia-connect
|
|
2
2
|
|
|
3
|
-
π Smart frontendβbackend connector with built-in mocking, fallback, and
|
|
3
|
+
π Smart frontendβbackend connector with built-in mocking, fallback, and auto-mocking.
|
|
4
4
|
|
|
5
|
-
Auravia Connect is a lightweight HTTP client
|
|
5
|
+
Auravia Connect is a lightweight HTTP client that keeps your frontend moving β even when your backend isnβt ready.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
## β¨
|
|
9
|
+
## β¨ Why auravia-connect?
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
Most tools only send requests.
|
|
12
|
+
Auravia goes further:
|
|
13
|
+
|
|
14
|
+
* π Simple HTTP client
|
|
15
|
+
* π§ͺ Built-in mocking
|
|
16
|
+
* π Smart fallback when network fails
|
|
17
|
+
* β‘ Auto mock when backend is unavailable
|
|
18
|
+
* π§© Request & response interceptors
|
|
19
|
+
* π§ Debug timeline
|
|
20
|
+
* π¦ Zero dependencies
|
|
21
|
+
* β‘ Lightweight
|
|
22
|
+
|
|
23
|
+
π **Your UI keeps working β even when your backend doesnβt.**
|
|
22
24
|
|
|
23
25
|
---
|
|
24
26
|
|
|
25
27
|
## π¦ Installation
|
|
26
28
|
|
|
27
29
|
```bash
|
|
28
|
-
npm install auravia-connect
|
|
30
|
+
npm install auravia-connect
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## π Quick Start
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const { createClient } = require("auravia-connect");
|
|
39
|
+
|
|
40
|
+
const api = createClient({
|
|
41
|
+
baseURL: "https://api.example.com"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
async function run() {
|
|
45
|
+
const res = await api.get("/users");
|
|
46
|
+
console.log(res.data);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
run();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## π§ͺ Manual Mocking
|
|
55
|
+
|
|
56
|
+
Use manual mocks when you want full control over fake data.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const api = createClient({
|
|
60
|
+
mock: true,
|
|
61
|
+
debug: true
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
api.mock("/users", {
|
|
65
|
+
id: "number",
|
|
66
|
+
name: "text"
|
|
67
|
+
}, { count: 3 });
|
|
68
|
+
|
|
69
|
+
const res = await api.get("/users");
|
|
70
|
+
console.log(res.data);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
β
Works without a backend.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## π― Wildcard Routes
|
|
78
|
+
|
|
79
|
+
Auravia supports dynamic routes.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
api.mock("/users/:id", {
|
|
83
|
+
id: "number",
|
|
84
|
+
name: "text"
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await api.get("/users/42");
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## π Smart Fallback
|
|
93
|
+
|
|
94
|
+
Automatically return mock when network fails.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const api = createClient({
|
|
98
|
+
baseURL: "http://localhost:5000",
|
|
99
|
+
mock: true,
|
|
100
|
+
mockFallback: true,
|
|
101
|
+
debug: true
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Flow**
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
network fails β fallback mock used
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## β‘ Auto Mock Mode (β Standout Feature)
|
|
114
|
+
|
|
115
|
+
Auravia can generate smart fake data automatically β no manual mocks needed.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const api = createClient({
|
|
119
|
+
autoMock: true,
|
|
120
|
+
debug: true
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const res = await api.get("/users");
|
|
124
|
+
console.log(res.data);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Example output**
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
{
|
|
131
|
+
id: 123,
|
|
132
|
+
name: "Sample text",
|
|
133
|
+
active: true
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### When AutoMock runs
|
|
138
|
+
|
|
139
|
+
AutoMock triggers when:
|
|
140
|
+
|
|
141
|
+
* β no manual mock exists
|
|
142
|
+
* β network request fails
|
|
143
|
+
* β
`autoMock: true` is enabled
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## βοΈ Mock Strategy
|
|
148
|
+
|
|
149
|
+
Control whether to prefer mock or network.
|
|
150
|
+
|
|
151
|
+
### Prefer mock (default)
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
createClient({
|
|
155
|
+
mock: true,
|
|
156
|
+
mockStrategy: "prefer-mock"
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Flow**
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
mock exists β return immediately
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Prefer network first
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
createClient({
|
|
172
|
+
mock: true,
|
|
173
|
+
mockFallback: true,
|
|
174
|
+
mockStrategy: "prefer-network"
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Flow**
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
try network β if fails β fallback mock
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## π§© Interceptors
|
|
187
|
+
|
|
188
|
+
### Request interceptor
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
api.onRequest((config) => {
|
|
192
|
+
config.headers.Authorization = "Bearer token";
|
|
193
|
+
return config;
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Response interceptor
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
api.onResponse((response) => {
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
console.error("API Error:", response.error);
|
|
203
|
+
}
|
|
204
|
+
return response;
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## π§ Debug Timeline
|
|
211
|
+
|
|
212
|
+
Enable detailed request logs.
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
const api = createClient({
|
|
216
|
+
debug: true
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Example output**
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
[auravia] β GET /users
|
|
224
|
+
[auravia] β¦ trying network
|
|
225
|
+
[auravia] β‘ auto mock generated
|
|
226
|
+
[auravia] β± 42ms
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## π API Reference
|
|
232
|
+
|
|
233
|
+
### createClient(config)
|
|
234
|
+
|
|
235
|
+
Creates a new client instance.
|
|
236
|
+
|
|
237
|
+
| Option | Type | Description |
|
|
238
|
+
| ------------ | ------- | ------------------------------------- |
|
|
239
|
+
| baseURL | string | Base API URL |
|
|
240
|
+
| headers | object | Default headers |
|
|
241
|
+
| timeout | number | Request timeout (ms) |
|
|
242
|
+
| mock | boolean | Enable manual mocks |
|
|
243
|
+
| mockFallback | boolean | Enable fallback to mock |
|
|
244
|
+
| autoMock | boolean | Enable automatic mock generation |
|
|
245
|
+
| debug | boolean | Enable debug logs |
|
|
246
|
+
| mockStrategy | string | `"prefer-mock"` or `"prefer-network"` |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### api.mock(url, response, options)
|
|
251
|
+
|
|
252
|
+
Register a manual mock.
|
|
253
|
+
|
|
254
|
+
**Built-in generators**
|
|
255
|
+
|
|
256
|
+
* `"text"`
|
|
257
|
+
* `"number"`
|
|
258
|
+
* `"boolean"`
|
|
259
|
+
* `"uuid"`
|
|
260
|
+
* `"image"`
|
|
261
|
+
* `"video"`
|
|
262
|
+
* `"mp3"`
|
|
263
|
+
|
|
264
|
+
**Example**
|
|
265
|
+
|
|
266
|
+
```js
|
|
267
|
+
api.mock("/profile", {
|
|
268
|
+
id: "number",
|
|
269
|
+
avatar: "image"
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
-
|
|
274
|
+
|
|
275
|
+
## π€ Contributing
|
|
276
|
+
|
|
277
|
+
Issues and PRs are welcome.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## π License
|
|
282
|
+
|
|
283
|
+
MIT Β© Dinesh R
|