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