phantomback 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.
Files changed (2) hide show
  1. package/README.md +153 -202
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,85 +1,76 @@
1
1
  <div align="center">
2
2
 
3
+ <br />
4
+
3
5
  # ๐Ÿ‘ป PhantomBack
4
6
 
5
- ### Instant Fake Backend Generator with Smart Responses
7
+ **Instant Fake Backend Generator with Smart Responses**
6
8
 
7
9
  [![npm version](https://img.shields.io/npm/v/phantomback.svg?style=flat-square&color=a78bfa)](https://www.npmjs.com/package/phantomback)
10
+ [![downloads](https://img.shields.io/npm/dm/phantomback.svg?style=flat-square&color=a78bfa)](https://www.npmjs.com/package/phantomback)
8
11
  [![license](https://img.shields.io/npm/l/phantomback.svg?style=flat-square)](LICENSE)
9
12
  [![node](https://img.shields.io/node/v/phantomback.svg?style=flat-square)](package.json)
10
- [![docs](https://img.shields.io/badge/docs-phantomback-a78bfa?style=flat-square)](https://phantombackxdocs.vercel.app)
11
-
12
- **Stop waiting for the backend. Start building now.**
13
-
14
- Drop in your API schema โ†’ get a fully functional REST server with realistic data,
15
- JWT auth, pagination, filtering, sorting, search, and nested routes โ€” in seconds.
16
13
 
17
- [Getting Started](https://phantombackxdocs.vercel.app/getting-started) ยท [Config Guide](https://phantombackxdocs.vercel.app/configuration) ยท [API Reference](https://phantombackxdocs.vercel.app/api-reference) ยท [Examples](https://phantombackxdocs.vercel.app/examples)
14
+ Stop waiting for the backend. Drop in your API schema โ†’ get a fully functional REST server with
15
+ realistic data, JWT auth, pagination, filtering, sorting, search, and nested routes โ€” in seconds.
18
16
 
19
- [Documentation](https://phantombackxdocs.vercel.app) ยท [npm](https://www.npmjs.com/package/phantomback) ยท [GitHub](https://github.com/madhavxchaturvedi/npm-phantomback)
17
+ [Documentation](https://phantombackxdocs.vercel.app) ยท
18
+ [Getting Started](https://phantombackxdocs.vercel.app/docs/getting-started) ยท
19
+ [API Reference](https://phantombackxdocs.vercel.app/docs/api-reference) ยท
20
+ [Playground](https://phantombackxdocs.vercel.app/docs/playground) ยท
21
+ [GitHub](https://github.com/madhavxchaturvedi/npm-phantomback)
20
22
 
21
- Made by [Madhav Chaturvedi](https://madhavxchaturvedi.vercel.app) ยท [LinkedIn](https://www.linkedin.com/in/madhavxchaturvedi/) ยท [Instagram](https://www.instagram.com/madhavxchaturvedi)
23
+ <br />
22
24
 
23
25
  </div>
24
26
 
25
27
  ---
26
28
 
27
- ## โœจ Features
28
-
29
- - ๐Ÿš€ **Zero-config mode** โ€” one command, full working API
30
- - ๐Ÿ“ฆ **Auto CRUD** โ€” GET, POST, PUT, PATCH, DELETE for every resource
31
- - ๐ŸŽญ **Realistic data** โ€” powered by Faker.js (names, emails, prices, avatars...)
32
- - ๐Ÿ“„ **Pagination** โ€” `?page=1&limit=10` with total counts & page metadata
33
- - ๐Ÿ” **Search** โ€” `?q=term` full-text search across all fields
34
- - ๐ŸŽฏ **Filtering** โ€” `?role=admin`, `?age_gte=18`, `?price_lte=100`, `?name_like=john`
35
- - โ†•๏ธ **Sorting** โ€” `?sort=-price`, `?sort=name,createdAt`
36
- - ๐Ÿ”— **Relations & Nested Routes** โ€” `GET /users/:id/posts` auto-detected from foreign keys
37
- - ๐Ÿ”’ **JWT Auth** โ€” register, login, protected routes with Bearer tokens
38
- - โฑ๏ธ **Response Delay** โ€” simulate slow networks with fixed or random latency
39
- - โœ… **Validation** โ€” required fields, type checks, unique constraints, email format
40
- - ๐Ÿ–ฅ๏ธ **CLI + Library** โ€” use as a CLI tool or import in your code
41
- - ๐Ÿง  **Smart Defaults** โ€” sensible conventions, override only what you need
29
+ ## Why PhantomBack?
30
+
31
+ | Pain point | PhantomBack fix |
32
+ |---|---|
33
+ | Backend not ready yet | Full REST API in one command |
34
+ | Static JSON mocks feel fake | Stateful CRUD with realistic Faker data |
35
+ | No pagination / filtering in mocks | Full query support out of the box |
36
+ | Auth testing is painful | JWT auth simulation built-in |
37
+ | Mock server setup takes time | One command or one line of code |
42
38
 
43
39
  ---
44
40
 
45
- ## ๐Ÿ“ฆ Installation
41
+ ## Quick Start
46
42
 
47
- ```bash
48
- # Global install (recommended for CLI)
49
- npm install -g phantomback
43
+ ### Install
50
44
 
51
- # Or as a dev dependency in your project
52
- npm install --save-dev phantomback
45
+ ```bash
46
+ npm install -g phantomback # CLI (global)
47
+ npm install --save-dev phantomback # Library (project)
53
48
  ```
54
49
 
55
- ---
56
-
57
- ## ๐Ÿš€ Quick Start
58
-
59
- ### One command โ€” full API:
50
+ ### Zero-config โ€” one command, full API
60
51
 
61
52
  ```bash
62
53
  phantomback start --zero
63
54
  ```
64
55
 
65
- That's it. You now have a REST API running at `http://localhost:3777` with:
66
- - ๐Ÿ‘ค 25 Users (protected with auth)
67
- - ๐Ÿ“ 50 Posts
68
- - ๐Ÿ’ฌ 100 Comments
69
- - ๐Ÿ“ฆ 30 Products
70
- - โœ… 40 Todos
56
+ You now have a REST API at **`http://localhost:3777`** with:
71
57
 
72
- ### Or with your own config:
58
+ | Resource | Count | Auth |
59
+ |---|---|---|
60
+ | `/api/users` | 25 records | ๐Ÿ”’ Protected |
61
+ | `/api/posts` | 50 records | โ€” |
62
+ | `/api/comments` | 100 records | โ€” |
63
+ | `/api/products` | 30 records | โ€” |
64
+ | `/api/todos` | 40 records | โ€” |
73
65
 
74
- ```bash
75
- # Generate a starter config
76
- phantomback init
66
+ ### Or bring your own schema
77
67
 
78
- # Edit phantom.config.js to your needs, then:
79
- phantomback start
68
+ ```bash
69
+ phantomback init # generates phantom.config.js
70
+ phantomback start # reads config and starts server
80
71
  ```
81
72
 
82
- ### Or as a library:
73
+ ### Or use as a library
83
74
 
84
75
  ```js
85
76
  import { createPhantom } from 'phantomback';
@@ -100,10 +91,10 @@ const server = await createPhantom({
100
91
 
101
92
  // server.stop() โ€” shut down
102
93
  // server.reset() โ€” re-seed all data
103
- // server.getStore() โ€” export current state as JSON
94
+ // server.getStore() โ€” export current state
104
95
  ```
105
96
 
106
- One line for zero-config:
97
+ One-liner for zero-config:
107
98
 
108
99
  ```js
109
100
  import { createPhantomZero } from 'phantomback';
@@ -112,18 +103,16 @@ await createPhantomZero(); // Full demo API on port 3777
112
103
 
113
104
  ---
114
105
 
115
- ## โš™๏ธ Configuration
106
+ ## Configuration
116
107
 
117
- Create a `phantom.config.js` in your project root:
108
+ Create **`phantom.config.js`** in your project root:
118
109
 
119
110
  ```js
120
111
  export default {
121
112
  port: 3777,
122
113
  prefix: '/api',
123
-
124
- // Global response latency (ms)
125
- // latency: 500,
126
- // latency: [200, 800], // random range
114
+ // latency: 500, // fixed delay (ms)
115
+ // latency: [200, 800], // random range
127
116
 
128
117
  auth: {
129
118
  secret: 'my-secret-key',
@@ -133,23 +122,23 @@ export default {
133
122
  resources: {
134
123
  users: {
135
124
  fields: {
136
- name: { type: 'name', required: true },
137
- email: { type: 'email', unique: true },
138
- age: { type: 'number', min: 18, max: 65 },
139
- role: { type: 'enum', values: ['admin', 'user', 'moderator'] },
140
- avatar: { type: 'avatar' },
125
+ name: { type: 'name', required: true },
126
+ email: { type: 'email', unique: true },
127
+ age: { type: 'number', min: 18, max: 65 },
128
+ role: { type: 'enum', values: ['admin', 'user', 'moderator'] },
129
+ avatar: { type: 'avatar' },
141
130
  isActive: { type: 'boolean' },
142
131
  },
143
- seed: 25, // auto-generate 25 records
132
+ seed: 25,
144
133
  auth: true, // protect with JWT
145
134
  },
146
135
 
147
136
  posts: {
148
137
  fields: {
149
- title: { type: 'title', required: true },
150
- body: { type: 'paragraphs', count: 3 },
138
+ title: { type: 'title', required: true },
139
+ body: { type: 'paragraphs', count: 3 },
151
140
  userId: { type: 'relation', resource: 'users' },
152
- views: { type: 'number', min: 0, max: 10000 },
141
+ views: { type: 'number', min: 0, max: 10000 },
153
142
  },
154
143
  seed: 50,
155
144
  },
@@ -157,43 +146,29 @@ export default {
157
146
  };
158
147
  ```
159
148
 
160
- ### Supported Field Types
149
+ > **Full config reference โ†’** [phantombackxdocs.vercel.app/docs/configuration](https://phantombackxdocs.vercel.app/docs/configuration)
150
+
151
+ ---
152
+
153
+ ## Supported Field Types
161
154
 
162
155
  | Type | Generates | Options |
163
- |------|-----------|---------|
164
- | `name` | Full name | โ€” |
165
- | `firstName` | First name | โ€” |
166
- | `lastName` | Last name | โ€” |
167
- | `username` | Username | โ€” |
168
- | `email` | Email address | `unique: true` |
169
- | `avatar` | Avatar URL | โ€” |
156
+ |---|---|---|
157
+ | `name` `firstName` `lastName` `username` | Names | โ€” |
158
+ | `email` | Email | `unique` |
170
159
  | `phone` | Phone number | โ€” |
171
- | `bio` | Short bio | โ€” |
172
- | `jobTitle` | Job title | โ€” |
173
- | `sentence` | One sentence | โ€” |
174
- | `paragraph` | One paragraph | โ€” |
175
- | `paragraphs` | Multiple paragraphs | `count: 3` |
176
- | `title` | Short title | โ€” |
177
- | `description` | 2-4 sentences | โ€” |
178
- | `slug` | URL slug | โ€” |
179
- | `number` | Integer | `min`, `max` |
180
- | `float` | Decimal | `min`, `max`, `precision` |
181
- | `price` | Price string | โ€” |
182
- | `rating` | 1.0 โ€“ 5.0 | โ€” |
183
- | `boolean` | true/false | โ€” |
184
- | `date` | ISO date | โ€” |
185
- | `pastDate` | Past date | โ€” |
186
- | `futureDate` | Future date | โ€” |
187
- | `url` | URL | โ€” |
188
- | `image` | Image URL | โ€” |
189
- | `color` | Color name | โ€” |
190
- | `address` | Street address | โ€” |
191
- | `city` | City name | โ€” |
192
- | `country` | Country name | โ€” |
193
- | `product` | Product name | โ€” |
194
- | `company` | Company name | โ€” |
160
+ | `avatar` | Avatar URL | โ€” |
161
+ | `bio` `jobTitle` | Profile text | โ€” |
162
+ | `sentence` `paragraph` `paragraphs` | Text blocks | `count` |
163
+ | `title` `description` `slug` | Content | โ€” |
164
+ | `number` `float` `price` `rating` | Numbers | `min` `max` `precision` |
165
+ | `boolean` | true / false | โ€” |
166
+ | `date` `pastDate` `futureDate` | ISO dates | โ€” |
167
+ | `url` `image` `color` | Misc | โ€” |
168
+ | `address` `city` `country` | Location | โ€” |
169
+ | `product` `company` | Business | โ€” |
195
170
  | `enum` | Random from list | `values: [...]` |
196
- | `relation` | Foreign key | `resource: 'users'` |
171
+ | `relation` | Foreign key | `resource: '...'` |
197
172
  | `uuid` | UUID string | โ€” |
198
173
 
199
174
  ### Field Options
@@ -201,60 +176,81 @@ export default {
201
176
  ```js
202
177
  {
203
178
  type: 'email',
204
- required: true, // validation: must be present
205
- unique: true, // validation: no duplicates
206
- min: 0, // for numbers: minimum value
207
- max: 100, // for numbers: maximum value
179
+ required: true, // must be present on create
180
+ unique: true, // no duplicates allowed
181
+ min: 0, // number minimum
182
+ max: 100, // number maximum
208
183
  }
209
184
  ```
210
185
 
211
186
  ---
212
187
 
213
- ## ๐Ÿ›ฃ๏ธ Auto-Generated Routes
188
+ ## Auto-Generated Routes
214
189
 
215
- For each resource (e.g., `users`), PhantomBack generates:
190
+ Every resource gets full CRUD automatically:
216
191
 
217
192
  | Method | Endpoint | Description |
218
- |--------|----------|-------------|
193
+ |---|---|---|
219
194
  | `GET` | `/api/users` | List all (paginated) |
220
- | `GET` | `/api/users/:id` | Get one by ID |
221
- | `POST` | `/api/users` | Create new |
195
+ | `GET` | `/api/users/:id` | Get one |
196
+ | `POST` | `/api/users` | Create |
222
197
  | `PUT` | `/api/users/:id` | Full update |
223
198
  | `PATCH` | `/api/users/:id` | Partial update |
224
199
  | `DELETE` | `/api/users/:id` | Delete |
225
200
 
226
- ### Nested Routes (auto-detected from relations)
201
+ ### Nested Routes
227
202
 
228
- If `posts` has `userId: { type: 'relation', resource: 'users' }`, you get:
203
+ If `posts` has `userId: { type: 'relation', resource: 'users' }`, you automatically get:
229
204
 
230
205
  ```
231
- GET /api/users/:id/posts โ†’ all posts by this user
206
+ GET /api/users/:id/posts โ†’ all posts by this user
232
207
  ```
233
208
 
234
209
  ### Special Routes
235
210
 
236
211
  | Method | Endpoint | Description |
237
- |--------|----------|-------------|
212
+ |---|---|---|
238
213
  | `GET` | `/api` | List all endpoints |
239
- | `GET` | `/api/_health` | Server health check |
240
- | `POST` | `/api/auth/register` | Register (email + password) |
241
- | `POST` | `/api/auth/login` | Login (returns JWT) |
242
- | `GET` | `/api/auth/me` | Current user (requires token) |
214
+ | `GET` | `/api/_health` | Health check |
215
+ | `POST` | `/api/auth/register` | Register |
216
+ | `POST` | `/api/auth/login` | Login โ†’ JWT |
217
+ | `GET` | `/api/auth/me` | Current user (token required) |
243
218
 
244
219
  ---
245
220
 
246
- ## ๐Ÿ” Query Parameters
247
-
248
- ### Pagination
221
+ ## Query Parameters
249
222
 
250
223
  ```bash
224
+ # Pagination
251
225
  GET /api/users?page=2&limit=10
252
226
  GET /api/users?offset=20&limit=10
227
+
228
+ # Filtering
229
+ GET /api/users?role=admin # exact match
230
+ GET /api/users?age_gte=18 # โ‰ฅ
231
+ GET /api/users?age_lte=30 # โ‰ค
232
+ GET /api/users?age_gt=18&age_lt=30 # range
233
+ GET /api/users?role_ne=admin # not equal
234
+ GET /api/users?name_like=john # contains
235
+
236
+ # Sorting
237
+ GET /api/users?sort=name # ascending
238
+ GET /api/users?sort=-name # descending
239
+ GET /api/users?sort=role,-age # multi-field
240
+
241
+ # Search
242
+ GET /api/users?q=john # full-text across all fields
243
+
244
+ # Field Selection
245
+ GET /api/users?fields=name,email,role
253
246
  ```
254
247
 
255
- Response includes:
248
+ Response includes pagination metadata:
249
+
256
250
  ```json
257
251
  {
252
+ "success": true,
253
+ "data": [ ... ],
258
254
  "meta": {
259
255
  "page": 2,
260
256
  "limit": 10,
@@ -266,91 +262,47 @@ Response includes:
266
262
  }
267
263
  ```
268
264
 
269
- ### Filtering
270
-
271
- ```bash
272
- GET /api/users?role=admin # exact match
273
- GET /api/users?age_gte=18 # greater than or equal
274
- GET /api/users?age_lte=30 # less than or equal
275
- GET /api/users?age_gt=18 # greater than
276
- GET /api/users?age_lt=30 # less than
277
- GET /api/users?role_ne=admin # not equal
278
- GET /api/users?name_like=john # contains (case-insensitive)
279
- ```
280
-
281
- ### Sorting
282
-
283
- ```bash
284
- GET /api/users?sort=name # ascending
285
- GET /api/users?sort=-name # descending
286
- GET /api/users?sort=role,-age # multi-field
287
- ```
288
-
289
- ### Search
290
-
291
- ```bash
292
- GET /api/users?q=john # search across all fields
293
- ```
294
-
295
- ### Field Selection
296
-
297
- ```bash
298
- GET /api/users?fields=name,email,role # only return these fields
299
- ```
300
-
301
265
  ---
302
266
 
303
- ## ๐Ÿ”’ Authentication
267
+ ## Authentication
304
268
 
305
- 1. **Register:**
306
269
  ```bash
270
+ # 1. Register
307
271
  curl -X POST http://localhost:3777/api/auth/register \
308
272
  -H "Content-Type: application/json" \
309
- -d '{"email": "user@example.com", "password": "secret123", "name": "John"}'
310
- ```
273
+ -d '{"email": "user@test.com", "password": "secret123", "name": "John"}'
311
274
 
312
- 2. **Login:**
313
- ```bash
275
+ # 2. Login
314
276
  curl -X POST http://localhost:3777/api/auth/login \
315
277
  -H "Content-Type: application/json" \
316
- -d '{"email": "user@example.com", "password": "secret123"}'
317
- ```
278
+ -d '{"email": "user@test.com", "password": "secret123"}'
318
279
 
319
- 3. **Access protected routes:**
320
- ```bash
280
+ # 3. Use the token
321
281
  curl http://localhost:3777/api/users \
322
282
  -H "Authorization: Bearer <your-token>"
323
283
  ```
324
284
 
325
285
  ---
326
286
 
327
- ## ๐Ÿ’ป CLI Reference
287
+ ## CLI Reference
328
288
 
329
289
  ```bash
330
- # Start with auto-detected config file
331
- phantomback start
332
-
333
- # Start with zero-config (demo mode)
334
- phantomback start --zero
335
-
336
- # Custom port
337
- phantomback start --port 4000
338
-
339
- # Specific config file
290
+ phantomback start # start with phantom.config.js
291
+ phantomback start --zero # zero-config demo mode
292
+ phantomback start --port 4000 # custom port
340
293
  phantomback start --config ./my-api.config.js
341
-
342
- # Generate starter config
343
- phantomback init
344
-
345
- # Show help
294
+ phantomback init # generate starter config
346
295
  phantomback --help
347
296
  ```
348
297
 
298
+ > **Full CLI docs โ†’** [phantombackxdocs.vercel.app/docs/cli](https://phantombackxdocs.vercel.app/docs/cli)
299
+
349
300
  ---
350
301
 
351
- ## ๐Ÿ—๏ธ Real-World Examples
302
+ ## Real-World Examples
352
303
 
353
- ### Hospital Management
304
+ <details>
305
+ <summary><strong>๐Ÿฅ Hospital Management</strong></summary>
354
306
 
355
307
  ```js
356
308
  export default {
@@ -376,8 +328,10 @@ export default {
376
328
  },
377
329
  };
378
330
  ```
331
+ </details>
379
332
 
380
- ### E-Commerce
333
+ <details>
334
+ <summary><strong>๐Ÿ›’ E-Commerce</strong></summary>
381
335
 
382
336
  ```js
383
337
  export default {
@@ -403,12 +357,13 @@ export default {
403
357
  },
404
358
  };
405
359
  ```
360
+ </details>
406
361
 
407
- ---
362
+ > **More examples โ†’** [phantombackxdocs.vercel.app/docs/examples](https://phantombackxdocs.vercel.app/docs/examples)
408
363
 
409
- ## ๐Ÿ“œ Response Format
364
+ ---
410
365
 
411
- All responses follow a consistent format:
366
+ ## Response Format
412
367
 
413
368
  **Success:**
414
369
  ```json
@@ -423,10 +378,7 @@ All responses follow a consistent format:
423
378
  ```json
424
379
  {
425
380
  "success": false,
426
- "error": {
427
- "status": 404,
428
- "message": "users with id \"abc\" not found"
429
- }
381
+ "error": { "status": 404, "message": "users with id \"abc\" not found" }
430
382
  }
431
383
  ```
432
384
 
@@ -437,28 +389,27 @@ All responses follow a consistent format:
437
389
  "error": {
438
390
  "status": 400,
439
391
  "message": "Validation failed",
440
- "details": [
441
- { "field": "email", "message": "\"email\" is required" }
442
- ]
392
+ "details": [{ "field": "email", "message": "\"email\" is required" }]
443
393
  }
444
394
  }
445
395
  ```
446
396
 
447
397
  ---
448
398
 
449
- ## ๐ŸŒŸ Why PhantomBack?
399
+ ## License
450
400
 
451
- | Problem | PhantomBack Solution |
452
- |---------|---------------------|
453
- | Backend not ready yet | Start frontend dev instantly |
454
- | Static JSON mocks are unrealistic | Stateful CRUD with realistic Faker data |
455
- | No pagination/filtering in mocks | Full query support out of the box |
456
- | Auth testing is painful | JWT auth simulation built-in |
457
- | Setting up mock servers takes time | One command / one line of code |
458
- | Different projects need different schemas | Define any resource with a config file |
401
+ MIT ยฉ [Madhav Chaturvedi](https://github.com/madhavxchaturvedi)
459
402
 
460
403
  ---
461
404
 
462
- ## ๐Ÿ“„ License
405
+ <div align="center">
406
+
407
+ [Documentation](https://phantombackxdocs.vercel.app) ยท
408
+ [npm](https://www.npmjs.com/package/phantomback) ยท
409
+ [GitHub](https://github.com/madhavxchaturvedi/npm-phantomback) ยท
410
+ [CLI Reference](https://phantombackxdocs.vercel.app/docs/cli) ยท
411
+ [Playground](https://phantombackxdocs.vercel.app/docs/playground)
463
412
 
464
- MIT ยฉ [Madhav Chaturvedi](https://github.com/madhavxchaturvedi)
413
+ Made with โค๏ธ by [Madhav Chaturvedi](https://madhavxchaturvedi.vercel.app) ยท [LinkedIn](https://www.linkedin.com/in/madhavxchaturvedi/) ยท [Instagram](https://www.instagram.com/madhavxchaturvedi)
414
+
415
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phantomback",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Instant fake backend generator with smart responses & chaos engineering. Drop in your API schema โ†’ get a fully functional, stateful REST server with realistic data, auth, pagination, filtering, and Reality Mode for chaos testing.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",