nest-scramble 1.1.1 → 1.3.0

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
@@ -55,9 +55,31 @@ Nest-Scramble is engineered using cutting-edge static analysis techniques that t
55
55
 
56
56
  This approach delivers what runtime reflection simply cannot: perfect accuracy, zero overhead, and future-proof compatibility with TypeScript's evolving type system.
57
57
 
58
- ## ⚡ Quick Start (3 Steps)
58
+ ## ⚡ Quick Start - Zero Config (2 Steps!)
59
59
 
60
- ### 1. Install the Package
60
+ ### Option A: Auto-Injection (Recommended - 30 seconds!)
61
+
62
+ ```bash
63
+ # 1. Install
64
+ npm install nest-scramble
65
+
66
+ # 2. Auto-inject into your project
67
+ npx nest-scramble init
68
+
69
+ # 3. Start your app
70
+ npm run start:dev
71
+
72
+ # 🎉 Done! Visit http://localhost:3000/docs
73
+ ```
74
+
75
+ The `init` command automatically:
76
+ - ✅ Adds the import statement to your `app.module.ts`
77
+ - ✅ Injects `NestScrambleModule.forRoot()` into your imports
78
+ - ✅ Uses smart defaults with zero configuration needed
79
+
80
+ ### Option B: Manual Installation (3 Steps)
81
+
82
+ #### 1. Install the Package
61
83
 
62
84
  ```bash
63
85
  # Using npm
@@ -70,42 +92,73 @@ yarn add nest-scramble
70
92
  pnpm add nest-scramble
71
93
  ```
72
94
 
73
- ### 2. Import Module in Your NestJS App
95
+ #### 2. Import Module in Your NestJS App
74
96
 
75
- Open your `app.module.ts` (or main module) and add:
97
+ **Zero-Config (Recommended):**
98
+ ```typescript
99
+ import { Module } from '@nestjs/common';
100
+ import { NestScrambleModule } from 'nest-scramble';
76
101
 
102
+ @Module({
103
+ imports: [
104
+ NestScrambleModule.forRoot(), // 🎯 That's it! Zero config needed
105
+ ],
106
+ })
107
+ export class AppModule {}
108
+ ```
109
+
110
+ **With Custom Options:**
77
111
  ```typescript
78
112
  import { Module } from '@nestjs/common';
79
113
  import { NestScrambleModule } from 'nest-scramble';
80
114
 
81
115
  @Module({
82
116
  imports: [
83
- // Your other modules...
84
117
  NestScrambleModule.forRoot({
85
- sourcePath: 'src', // Path to your source code
86
- baseUrl: 'http://localhost:3000',
87
- enableMock: true, // Enable mock endpoints
88
- autoExportPostman: false, // Auto-generate Postman collection
118
+ sourcePath: 'src', // Auto-detected by default
119
+ baseUrl: 'http://localhost:3000', // Auto-detected from PORT env
120
+ enableMock: true, // Enabled by default
121
+ autoExportPostman: false, // Disabled by default
122
+ apiTitle: 'My API', // Auto-detected from package.json
123
+ apiVersion: '1.0.0', // Auto-detected from package.json
89
124
  }),
90
125
  ],
91
126
  })
92
127
  export class AppModule {}
93
128
  ```
94
129
 
95
- ### 3. Start Your App and Visit Documentation
130
+ #### 3. Start Your App and Visit Documentation
96
131
 
97
132
  ```bash
98
133
  npm run start:dev
99
134
  ```
100
135
 
136
+ You'll see a beautiful dashboard in your terminal:
137
+
138
+ ```
139
+ ┌──────────────────────────────────────────────────────────┐
140
+ │ 🚀 Nest-Scramble by Mohamed Mustafa is Active! │
141
+ ├──────────────────────────────────────────────────────────┤
142
+ │ 📖 Docs: http://localhost:3000/docs │
143
+ │ 📄 JSON: http://localhost:3000/docs-json │
144
+ │ 🎭 Mock: http://localhost:3000/scramble-mock │
145
+ │ ✨ Scanning: src │
146
+ │ 🎯 Controllers: 5 │
147
+ └──────────────────────────────────────────────────────────┘
148
+ ```
149
+
101
150
  Then open your browser:
102
151
 
103
152
  - **📖 Interactive API Docs (Scalar UI)**: http://localhost:3000/docs
104
153
  - **📄 OpenAPI JSON Spec**: http://localhost:3000/docs-json
105
154
  - **🎭 Mock Endpoints**: http://localhost:3000/scramble-mock/*
106
- - **📤 Postman Collection**: Auto-generated at `collection.json` (if enabled)
107
155
 
108
- **That's it!** Nest-Scramble will automatically scan your controllers and generate beautiful documentation.
156
+ **That's it!** Nest-Scramble automatically:
157
+ - 🔍 Detects your project structure
158
+ - 📂 Finds your controllers
159
+ - 📝 Generates OpenAPI spec
160
+ - 🎨 Serves beautiful documentation
161
+ - 🎭 Provides mock endpoints
109
162
 
110
163
  ## ⚙️ Configuration Options
111
164
 
@@ -177,40 +230,221 @@ GET /scramble-mock/users/123
177
230
  ## 🔧 Advanced Usage
178
231
 
179
232
  ### CLI Generation
233
+
234
+ The Nest-Scramble CLI allows you to generate API documentation without running your NestJS application.
235
+
236
+ #### Generate OpenAPI Specification
237
+
238
+ ```bash
239
+ # Using npx
240
+ npx nest-scramble generate src
241
+
242
+ # Using pnpm dlx
243
+ pnpm dlx nest-scramble generate src
244
+
245
+ # Using yarn dlx
246
+ yarn dlx nest-scramble generate src
247
+ ```
248
+
249
+ #### CLI Options
250
+
251
+ ```bash
252
+ nest-scramble generate <sourcePath> [options]
253
+
254
+ Options:
255
+ -o, --output <file> Output file path (default: "openapi.json")
256
+ -f, --format <type> Output format: openapi or postman (default: "openapi")
257
+ -b, --baseUrl <url> Base URL for the API (default: "http://localhost:3000")
258
+ -t, --title <title> API title (default: "NestJS API")
259
+ -v, --apiVersion <version> API version (default: "1.0.0")
260
+ -h, --help Display help for command
261
+ ```
262
+
263
+ #### Examples
264
+
265
+ **Generate OpenAPI JSON:**
266
+ ```bash
267
+ pnpm dlx nest-scramble generate src --output openapi.json
268
+ ```
269
+
270
+ **Generate Postman Collection:**
271
+ ```bash
272
+ pnpm dlx nest-scramble generate src --format postman --output collection.json
273
+ ```
274
+
275
+ **Custom API Details:**
276
+ ```bash
277
+ pnpm dlx nest-scramble generate src \
278
+ --output my-api.json \
279
+ --title "My Awesome API" \
280
+ --apiVersion "2.0.0" \
281
+ --baseUrl "https://api.example.com"
282
+ ```
283
+
284
+ **Check Version:**
180
285
  ```bash
181
- pnpm dlx nest-scramble generate src --output my-api.json
286
+ pnpm dlx nest-scramble --version
182
287
  ```
183
288
 
184
289
  ### Programmatic API
290
+
291
+ Use Nest-Scramble programmatically in your Node.js scripts:
292
+
185
293
  ```typescript
186
- import { ScannerService, OpenApiTransformer } from 'nest-scramble';
294
+ import { ScannerService, OpenApiTransformer, PostmanCollectionGenerator } from 'nest-scramble';
295
+ import * as fs from 'fs';
187
296
 
297
+ // Scan controllers
188
298
  const scanner = new ScannerService();
189
299
  const controllers = scanner.scanControllers('src');
190
300
 
191
- const transformer = new OpenApiTransformer();
192
- const spec = transformer.transform(controllers);
301
+ // Generate OpenAPI spec
302
+ const transformer = new OpenApiTransformer('http://localhost:3000');
303
+ const openApiSpec = transformer.transform(
304
+ controllers,
305
+ 'My API',
306
+ '1.0.0',
307
+ 'http://localhost:3000'
308
+ );
309
+
310
+ // Save to file
311
+ fs.writeFileSync('openapi.json', JSON.stringify(openApiSpec, null, 2));
312
+
313
+ // Or generate Postman collection
314
+ const postmanGen = new PostmanCollectionGenerator('http://localhost:3000');
315
+ const collection = postmanGen.generateCollection(controllers);
316
+ fs.writeFileSync('collection.json', JSON.stringify(collection, null, 2));
193
317
  ```
194
318
 
195
- ### Watch Mode
196
- ```bash
197
- pnpm run watch-generate
319
+ ### CI/CD Integration
320
+
321
+ Add to your CI/CD pipeline to auto-generate documentation:
322
+
323
+ ```yaml
324
+ # .github/workflows/docs.yml
325
+ name: Generate API Docs
326
+
327
+ on:
328
+ push:
329
+ branches: [main]
330
+
331
+ jobs:
332
+ generate-docs:
333
+ runs-on: ubuntu-latest
334
+ steps:
335
+ - uses: actions/checkout@v3
336
+ - uses: actions/setup-node@v3
337
+ with:
338
+ node-version: '18'
339
+ - run: npm install
340
+ - run: npx nest-scramble generate src --output openapi.json
341
+ - uses: actions/upload-artifact@v3
342
+ with:
343
+ name: api-docs
344
+ path: openapi.json
198
345
  ```
199
- Automatically regenerates docs on file changes.
200
346
 
201
- ## 🎨 Documentation UI
347
+ ## 🎨 Documentation UI - World-Class Design
202
348
 
203
- ### Built-in Scalar UI
349
+ ### Futuristic Theme (NEW!)
204
350
 
205
- Nest-Scramble comes with **Scalar UI** built-in via CDN. No additional packages needed!
351
+ Nest-Scramble now features a **bespoke, futuristic dashboard** that rivals high-end SaaS products like Stripe, Vercel, and Linear!
206
352
 
207
- When you visit `http://localhost:3000/docs`, you'll see a beautiful, interactive API documentation interface with:
353
+ **🚀 Key Features:**
354
+ - **Deep Space Dark Mode** - Ultra-premium `#050505` background
355
+ - **Glassmorphism Design** - Backdrop blur effects on all cards
356
+ - **Cyber Gradients** - Cyan-to-purple button animations
357
+ - **Animated Grid Background** - Subtle pulsing effect
358
+ - **Night Owl Code Theme** - Beautiful syntax highlighting
359
+ - **Custom Scrollbar** - Gradient styling throughout
360
+ - **Spotlight Search** - Cmd+K style search experience
361
+ - **Easter Egg Console** - Hidden developer messages ✨
362
+
363
+ ### 🎨 Theme Customization
364
+
365
+ **Futuristic Theme (Default):**
366
+ ```typescript
367
+ NestScrambleModule.forRoot({
368
+ theme: 'futuristic', // Modern, dark, glassmorphic
369
+ primaryColor: '#00f2ff', // Cyber-Cyan (default)
370
+ customDomainIcon: '/logo.png', // Your brand favicon
371
+ apiTitle: 'My Awesome API',
372
+ })
373
+ ```
374
+
375
+ **Classic Theme:**
376
+ ```typescript
377
+ NestScrambleModule.forRoot({
378
+ theme: 'classic', // Clean, light, professional
379
+ primaryColor: '#0066cc', // Corporate blue
380
+ apiTitle: 'Enterprise API',
381
+ })
382
+ ```
383
+
384
+ **Custom Color Branding:**
385
+ ```typescript
386
+ // One line changes the entire UI color scheme!
387
+ NestScrambleModule.forRoot({
388
+ primaryColor: '#a855f7', // Electric Purple
389
+ // or '#10b981' for Emerald Green
390
+ // or '#f59e0b' for Amber Orange
391
+ // or any hex color you want!
392
+ })
393
+ ```
394
+
395
+ ### 🎭 UI Configuration Options
396
+
397
+ | Option | Type | Default | Description |
398
+ |--------|------|---------|-------------|
399
+ | `theme` | `'classic' \| 'futuristic'` | `'futuristic'` | UI theme selection |
400
+ | `primaryColor` | `string` | `'#00f2ff'` | Primary accent color (hex) |
401
+ | `customDomainIcon` | `string` | `''` | Custom favicon URL |
402
+ | `apiTitle` | `string` | Auto-detected | API documentation title |
403
+ | `apiVersion` | `string` | Auto-detected | API version number |
404
+
405
+ ### 🌟 Interactive Features
406
+
407
+ When you visit `http://localhost:3000/docs`, you'll experience:
208
408
 
209
409
  - 🎯 **Interactive API Explorer** - Test endpoints directly from the browser
210
410
  - 📝 **Auto-generated Examples** - Request/response samples for all endpoints
211
- - 🔍 **Search Functionality** - Quickly find endpoints
212
- - 🌙 **Dark Mode Support** - Easy on the eyes
213
- - 📱 **Mobile Responsive** - Works on all devices
411
+ - 🔍 **Spotlight Search** - Quickly find endpoints with glowing focus states
412
+ - 🌙 **Futuristic Dark Mode** - Deep space theme with glassmorphism
413
+ - 📱 **Mobile Responsive** - Works beautifully on all devices
414
+ - 🎨 **Theme Toggle** - Switch between Futuristic and Classic (top-right button)
415
+ - ✨ **Powered by Badge** - Glowing brand badge with pulse animation
416
+ - 🎭 **Easter Eggs** - Check your browser console for surprises!
417
+
418
+ ### 🖥️ Terminal Dashboard
419
+
420
+ The startup dashboard now features **gradient styling** with ANSI colors:
421
+
422
+ ```
423
+ ╔═══════════════════════════════════════════════════════════════╗
424
+ ║ ✨ NEST-SCRAMBLE by Mohamed Mustafa ║
425
+ ║ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ║
426
+ ║ ║
427
+ ║ ● Documentation ║
428
+ ║ → http://localhost:3000/docs ║
429
+ ║ ║
430
+ ║ ● OpenAPI Spec ║
431
+ ║ → http://localhost:3000/docs-json ║
432
+ ║ ║
433
+ ║ ● Mock Server ║
434
+ ║ → http://localhost:3000/scramble-mock ║
435
+ ║ ║
436
+ ║ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ║
437
+ ║ 📦 Source Path: src ║
438
+ ║ 🎯 Controllers: 5 ║
439
+ ║ 🎨 Theme: Futuristic ║
440
+ ╚═══════════════════════════════════════════════════════════════╝
441
+ ```
442
+
443
+ ### 📚 More UI Documentation
444
+
445
+ For complete UI customization guide, see:
446
+ - **[UI_FEATURES.md](./UI_FEATURES.md)** - Comprehensive feature documentation
447
+ - **[examples/futuristic-ui-example.ts](./examples/futuristic-ui-example.ts)** - Usage examples
214
448
 
215
449
  ### Available Endpoints
216
450
 
@@ -335,7 +569,73 @@ npm install
335
569
  npm run build
336
570
  ```
337
571
 
338
- #### 4. **pnpm Dependency Conflicts**
572
+ #### 4. **"Unauthorized" (401) Error on /docs Endpoint**
573
+
574
+ If you have a Global AuthGuard and get 401 Unauthorized when accessing `/docs` or `/docs-json`:
575
+
576
+ **Solution:**
577
+
578
+ Nest-Scramble automatically marks its documentation endpoints as public using `@SetMetadata('isPublic', true)`. However, your AuthGuard needs to respect this metadata.
579
+
580
+ Update your AuthGuard to check for the `isPublic` metadata:
581
+
582
+ ```typescript
583
+ import { Injectable, ExecutionContext } from '@nestjs/common';
584
+ import { Reflector } from '@nestjs/core';
585
+ import { AuthGuard } from '@nestjs/passport';
586
+
587
+ @Injectable()
588
+ export class JwtAuthGuard extends AuthGuard('jwt') {
589
+ constructor(private reflector: Reflector) {
590
+ super();
591
+ }
592
+
593
+ canActivate(context: ExecutionContext) {
594
+ // Check if route is marked as public
595
+ const isPublic = this.reflector.getAllAndOverride<boolean>('isPublic', [
596
+ context.getHandler(),
597
+ context.getClass(),
598
+ ]);
599
+
600
+ if (isPublic) {
601
+ return true; // Allow access to public routes
602
+ }
603
+
604
+ return super.canActivate(context);
605
+ }
606
+ }
607
+ ```
608
+
609
+ **Alternative Solution - Exclude /docs path:**
610
+
611
+ ```typescript
612
+ import { Module } from '@nestjs/common';
613
+ import { APP_GUARD } from '@nestjs/core';
614
+
615
+ @Module({
616
+ providers: [
617
+ {
618
+ provide: APP_GUARD,
619
+ useClass: JwtAuthGuard,
620
+ },
621
+ ],
622
+ })
623
+ export class AppModule {}
624
+
625
+ // In your AuthGuard:
626
+ canActivate(context: ExecutionContext) {
627
+ const request = context.switchToHttp().getRequest();
628
+
629
+ // Skip authentication for documentation endpoints
630
+ if (request.url.startsWith('/docs')) {
631
+ return true;
632
+ }
633
+
634
+ return super.canActivate(context);
635
+ }
636
+ ```
637
+
638
+ #### 5. **pnpm Dependency Conflicts**
339
639
 
340
640
  If using pnpm and getting peer dependency warnings:
341
641
 
@@ -345,7 +645,7 @@ Nest-Scramble v1.1.0+ properly declares peer dependencies. Update to the latest
345
645
  pnpm update nest-scramble
346
646
  ```
347
647
 
348
- #### 5. **Controllers Not Being Scanned**
648
+ #### 6. **Controllers Not Being Scanned**
349
649
 
350
650
  The scanner looks in your **host project's** `src` folder, not the library's folder.
351
651
 
@@ -360,7 +660,7 @@ The scanner looks in your **host project's** `src` folder, not the library's fol
360
660
 
361
661
  3. Verify your `tsconfig.json` exists in the project root
362
662
 
363
- #### 6. **Mock Endpoints Not Working**
663
+ #### 7. **Mock Endpoints Not Working**
364
664
 
365
665
  If `/scramble-mock/*` returns 404:
366
666
 
@@ -369,7 +669,7 @@ If `/scramble-mock/*` returns 404:
369
669
  - The middleware applies to all routes matching `/scramble-mock/*`
370
670
  - Example: `http://localhost:3000/scramble-mock/users/123`
371
671
 
372
- #### 7. **OpenAPI Spec is Empty or Incomplete**
672
+ #### 8. **OpenAPI Spec is Empty or Incomplete**
373
673
 
374
674
  **Solution:**
375
675
  - Ensure your DTOs are TypeScript classes or interfaces (not plain objects)
@@ -397,7 +697,6 @@ If you're still experiencing issues:
397
697
  1. **Check the logs** - Nest-Scramble provides detailed diagnostic output on startup
398
698
  2. **Verify your version** - Run `npm list nest-scramble` (should be 1.1.0+)
399
699
  3. **Open an issue** - [GitHub Issues](https://github.com/Eng-MMustafa/nest-scramble/issues)
400
- 4. **Join discussions** - [GitHub Discussions](https://github.com/Eng-MMustafa/nest-scramble/discussions)
401
700
 
402
701
  When reporting issues, please include:
403
702
  - Nest-Scramble version