phantomback 2.0.0 → 2.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 +78 -26
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,18 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
# 👻 PhantomBack
|
|
6
6
|
|
|
7
|
-
**Instant Fake Backend
|
|
7
|
+
**Instant Fake Backend · Chaos Engineering · Reality Mode**
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/phantomback)
|
|
10
10
|
[](https://www.npmjs.com/package/phantomback)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](package.json)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
Two tools, one package — everything you need to build and harden frontends without a real backend.
|
|
15
|
+
|
|
16
|
+
**Fake Backend** — Drop in your API schema → get a fully functional REST server with realistic data, JWT auth, pagination, filtering, sorting, search, and nested routes in seconds.
|
|
17
|
+
|
|
18
|
+
**Reality Mode** — Flip one flag and your fake API starts behaving like a broken production server: random failures, latency spikes, connection drops, corrupted responses, and timeouts — so your error handling actually gets tested.
|
|
16
19
|
|
|
17
20
|
[Documentation](https://phantombackxdocs.vercel.app) ·
|
|
18
21
|
[Getting Started](https://phantombackxdocs.vercel.app/docs/getting-started) ·
|
|
22
|
+
[Reality Mode](https://phantombackxdocs.vercel.app/docs/reality-mode) ·
|
|
19
23
|
[API Reference](https://phantombackxdocs.vercel.app/docs/api-reference) ·
|
|
20
24
|
[Playground](https://phantombackxdocs.vercel.app/docs/playground) ·
|
|
21
25
|
[GitHub](https://github.com/madhavxchaturvedi/npm-phantomback)
|
|
@@ -28,6 +32,8 @@ realistic data, JWT auth, pagination, filtering, sorting, search, and nested rou
|
|
|
28
32
|
|
|
29
33
|
## Why PhantomBack?
|
|
30
34
|
|
|
35
|
+
**Fake Backend**
|
|
36
|
+
|
|
31
37
|
| Pain point | PhantomBack fix |
|
|
32
38
|
|---|---|
|
|
33
39
|
| Backend not ready yet | Full REST API in one command |
|
|
@@ -36,6 +42,16 @@ realistic data, JWT auth, pagination, filtering, sorting, search, and nested rou
|
|
|
36
42
|
| Auth testing is painful | JWT auth simulation built-in |
|
|
37
43
|
| Mock server setup takes time | One command or one line of code |
|
|
38
44
|
|
|
45
|
+
**Reality Mode — Chaos Engineering**
|
|
46
|
+
|
|
47
|
+
| Pain point | PhantomBack fix |
|
|
48
|
+
|---|---|
|
|
49
|
+
| Error handling never gets tested | Random 5xx failures on every request |
|
|
50
|
+
| Network issues are hard to reproduce | Configurable latency spikes and jitter |
|
|
51
|
+
| Connection drops catch you off guard | Simulated TCP drops via `connectionDropRate` |
|
|
52
|
+
| Bad JSON is untested | Malformed response injection via `corruptionRate` |
|
|
53
|
+
| Timeout handling is always skipped | Hanging responses via `timeoutRate` |
|
|
54
|
+
|
|
39
55
|
---
|
|
40
56
|
|
|
41
57
|
## Quick Start
|
|
@@ -101,6 +117,28 @@ import { createPhantomZero } from 'phantomback';
|
|
|
101
117
|
await createPhantomZero(); // Full demo API on port 3777
|
|
102
118
|
```
|
|
103
119
|
|
|
120
|
+
### Reality Mode — one flag, instant chaos
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
phantomback start --zero --chaos
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Your same fake API now randomly:
|
|
127
|
+
|
|
128
|
+
| What happens | How often (defaults) |
|
|
129
|
+
|---|---|
|
|
130
|
+
| Injects latency spikes (200–5000 ms) | ~30% of requests |
|
|
131
|
+
| Returns a random 5xx error | 10% of requests |
|
|
132
|
+
| Drops the TCP connection | 2% of requests |
|
|
133
|
+
| Sends malformed / partial JSON | 2% of requests |
|
|
134
|
+
| Hangs the response (~30 s) | 3% of requests |
|
|
135
|
+
|
|
136
|
+
Or enable with custom rates:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
phantomback start --chaos --chaos-failure 0.2 --chaos-latency 300,2000
|
|
140
|
+
```
|
|
141
|
+
|
|
104
142
|
---
|
|
105
143
|
|
|
106
144
|
## Configuration
|
|
@@ -286,41 +324,54 @@ curl http://localhost:3777/api/users \
|
|
|
286
324
|
|
|
287
325
|
## Reality Mode — Chaos Engineering
|
|
288
326
|
|
|
289
|
-
|
|
327
|
+
PhantomBack's second core feature. Once your fake API works, flip Reality Mode on to test how your frontend *actually* handles broken backends.
|
|
328
|
+
|
|
329
|
+
### Enable via CLI (quickest)
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
phantomback start --chaos # defaults
|
|
333
|
+
phantomback start --chaos --chaos-failure 0.2 # 20% failure rate
|
|
334
|
+
phantomback start --chaos --chaos-latency 500,3000 # 500–3000 ms jitter
|
|
335
|
+
```
|
|
290
336
|
|
|
291
|
-
Enable
|
|
337
|
+
### Enable via `phantom.config.js` (full control)
|
|
292
338
|
|
|
293
339
|
```js
|
|
294
340
|
export default {
|
|
295
|
-
|
|
341
|
+
port: 3777,
|
|
342
|
+
resources: { /* your schema */ },
|
|
343
|
+
|
|
296
344
|
chaos: {
|
|
297
345
|
enabled: true,
|
|
298
|
-
latency: { min: 200, max: 5000 }, //
|
|
299
|
-
failureRate: 0.1, // 10% random 5xx
|
|
300
|
-
errorCodes: [500, 502, 503, 504],
|
|
301
|
-
connectionDropRate: 0.02, // 2%
|
|
302
|
-
corruptionRate: 0.02, // 2% malformed JSON
|
|
303
|
-
timeoutRate: 0.03, // 3%
|
|
304
|
-
scenarios:
|
|
346
|
+
latency: { min: 200, max: 5000 }, // random delay range (ms)
|
|
347
|
+
failureRate: 0.1, // 10% → random 5xx response
|
|
348
|
+
errorCodes: [500, 502, 503, 504], // which 5xx codes to use
|
|
349
|
+
connectionDropRate: 0.02, // 2% → TCP connection drop
|
|
350
|
+
corruptionRate: 0.02, // 2% → malformed JSON body
|
|
351
|
+
timeoutRate: 0.03, // 3% → response hangs ~30 s
|
|
352
|
+
scenarios: ['latency', 'failure', 'drop', 'corruption', 'timeout'],
|
|
305
353
|
},
|
|
306
354
|
};
|
|
307
355
|
```
|
|
308
356
|
|
|
309
|
-
|
|
357
|
+
### Chaos Scenarios
|
|
310
358
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
359
|
+
| Scenario | Config Key | Rate | What your frontend sees |
|
|
360
|
+
|---|---|---|---|
|
|
361
|
+
| `latency` | `latency` | ~30% | Slow response — spinner never ends |
|
|
362
|
+
| `failure` | `failureRate` | 10% | Random 500 / 502 / 503 / 504 |
|
|
363
|
+
| `drop` | `connectionDropRate` | 2% | Network error — socket closed mid-flight |
|
|
364
|
+
| `corruption` | `corruptionRate` | 2% | `SyntaxError` — invalid JSON received |
|
|
365
|
+
| `timeout` | `timeoutRate` | 3% | Request hangs — no response for ~30 s |
|
|
316
366
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
367
|
+
### What to test with Reality Mode
|
|
368
|
+
|
|
369
|
+
- Loading states and spinners under slow networks
|
|
370
|
+
- Retry logic and exponential backoff
|
|
371
|
+
- Error boundaries and fallback UI
|
|
372
|
+
- Toast / notification error handling
|
|
373
|
+
- Request timeout cancellation (`AbortController`)
|
|
374
|
+
- Partial data rendering on corrupt responses
|
|
324
375
|
|
|
325
376
|
> **Full guide →** [phantombackxdocs.vercel.app/docs/reality-mode](https://phantombackxdocs.vercel.app/docs/reality-mode)
|
|
326
377
|
|
|
@@ -453,6 +504,7 @@ MIT © [Madhav Chaturvedi](https://github.com/madhavxchaturvedi)
|
|
|
453
504
|
[npm](https://www.npmjs.com/package/phantomback) ·
|
|
454
505
|
[GitHub](https://github.com/madhavxchaturvedi/npm-phantomback) ·
|
|
455
506
|
[CLI Reference](https://phantombackxdocs.vercel.app/docs/cli) ·
|
|
507
|
+
[Reality Mode](https://phantombackxdocs.vercel.app/docs/reality-mode) ·
|
|
456
508
|
[Playground](https://phantombackxdocs.vercel.app/docs/playground)
|
|
457
509
|
|
|
458
510
|
Made with ❤️ by [Madhav Chaturvedi](https://madhavxchaturvedi.vercel.app) · [LinkedIn](https://www.linkedin.com/in/madhavxchaturvedi/) · [Instagram](https://www.instagram.com/madhavxchaturvedi)
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phantomback",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Two tools, one package. Fake Backend: drop in your API schema → instant stateful REST server with realistic data, JWT auth, pagination, filtering & sorting. Reality Mode: flip one flag → random failures, latency spikes, connection drops & corrupted responses to harden your frontend.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
|
-
"phantomback": "
|
|
11
|
+
"phantomback": "bin/phantomback.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "node bin/phantomback.js start",
|