exguard-backend 1.0.3 → 1.0.4

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
@@ -25,13 +25,40 @@ pnpm add exguard-backend
25
25
 
26
26
  ## 🚀 Quick Start - NestJS Integration
27
27
 
28
- ### Step 1: Install Dependencies
28
+ ### 🎯 Option 1: Automatic Setup (Recommended)
29
+
30
+ **One-command setup for NestJS projects:**
31
+
32
+ ```bash
33
+ # Install exguard-backend
34
+ npm install exguard-backend
35
+
36
+ # Run automatic setup
37
+ npx exguard-backend setup-nestjs
38
+ # OR
39
+ npm run setup-nestjs
40
+ ```
41
+
42
+ **What the automatic setup creates:**
43
+
44
+ ✅ **ExGuard Module** - Global module with Guard provider
45
+ ✅ **Custom Guards** - ExGuardNestGuard, PermissionGuard, RoleGuard
46
+ ✅ **Decorators** - @RequirePermissions, @RequireRoles, @RequireModules
47
+ ✅ **Example Controller** - Complete usage examples
48
+ ✅ **Environment Variables** - .env configuration
49
+ ✅ **Package Scripts** - Helper scripts for development
50
+
51
+ ### 📋 Option 2: Manual Setup
52
+
53
+ If you prefer manual setup, follow these steps:
54
+
55
+ #### Step 1: Install Dependencies
29
56
 
30
57
  ```bash
31
58
  npm install exguard-backend @nestjs/core @nestjs/common @nestjs/platform-express
32
59
  ```
33
60
 
34
- ### Step 2: Create ExGuard Module
61
+ #### Step 2: Create ExGuard Module
35
62
 
36
63
  ```typescript
37
64
  // src/exguard/exguard.module.ts
@@ -54,7 +81,7 @@ import { Guard } from 'exguard-backend';
54
81
  export class ExGuardModule {}
55
82
  ```
56
83
 
57
- ### Step 3: Create Custom Guards
84
+ #### Step 3: Create Custom Guards
58
85
 
59
86
  ```typescript
60
87
  // src/exguard/exguard.guard.ts
@@ -104,7 +131,7 @@ export function createPermissionGuard(permissions: string[], requireAll = false)
104
131
  }
105
132
  ```
106
133
 
107
- ### Step 4: Protect Your Controllers
134
+ #### Step 4: Protect Your Controllers
108
135
 
109
136
  ```typescript
110
137
  // src/events/events.controller.ts
@@ -134,7 +161,7 @@ export class EventsController {
134
161
  }
135
162
  ```
136
163
 
137
- ### Step 5: Update App Module
164
+ #### Step 5: Update App Module
138
165
 
139
166
  ```typescript
140
167
  // src/app.module.ts
@@ -149,6 +176,41 @@ import { EventsController } from './events/events.controller';
149
176
  export class AppModule {}
150
177
  ```
151
178
 
179
+ ### 🎯 Automatic Setup Features
180
+
181
+ The automatic setup creates a complete NestJS integration:
182
+
183
+ #### **Generated Files:**
184
+ ```
185
+ src/
186
+ ├── exguard/
187
+ │ ├── exguard.module.ts # Global ExGuard module
188
+ │ ├── exguard.guard.ts # Custom guards
189
+ │ ├── exguard.decorators.ts # Permission decorators
190
+ │ └── guards/ # Additional guard files
191
+ ├── events/
192
+ │ └── events.controller.ts # Example controller
193
+ └── .env # Environment configuration
194
+ ```
195
+
196
+ #### **Generated Decorators:**
197
+ ```typescript
198
+ @RequirePermissions(['events:read'])
199
+ @RequireRoles(['Admin'])
200
+ @RequireModules(['reporting'])
201
+ @RequireFieldOffices(['FO-MANILA'])
202
+ ```
203
+
204
+ #### **Generated Package Scripts:**
205
+ ```json
206
+ {
207
+ "scripts": {
208
+ "exguard:setup": "node node_modules/exguard-backend/scripts/setup-nestjs.js",
209
+ "exguard:example": "node node_modules/exguard-backend/scripts/create-example.js"
210
+ }
211
+ }
212
+ ```
213
+
152
214
  ## 🎯 Advanced NestJS Examples
153
215
 
154
216
  ### Role-Based Protection
package/dist/index.d.cts CHANGED
@@ -51,17 +51,17 @@ interface ExGuardEnhancedConfig$1 extends ExGuardConfig {
51
51
  cache?: ExGuardCacheConfig;
52
52
  realtime?: ExGuardRealtimeConfig;
53
53
  }
54
- interface GuardContext$1 {
54
+ interface GuardContext {
55
55
  token: string;
56
56
  request?: any;
57
57
  }
58
- interface GuardResult$1 {
58
+ interface GuardResult {
59
59
  allowed: boolean;
60
60
  user?: UserAccessResponse;
61
61
  error?: string;
62
62
  statusCode?: number;
63
63
  }
64
- interface GuardOptions$1 {
64
+ interface GuardOptions {
65
65
  permissions?: string[];
66
66
  roles?: string[];
67
67
  modules?: string[];
@@ -292,23 +292,6 @@ declare const realtime: ExGuardRealtime;
292
292
  * Framework-agnostic guards for protecting backend endpoints
293
293
  */
294
294
 
295
- interface GuardContext {
296
- token: string;
297
- request?: any;
298
- }
299
- interface GuardResult {
300
- allowed: boolean;
301
- user?: UserAccessResponse;
302
- error?: string;
303
- statusCode?: number;
304
- }
305
- interface GuardOptions {
306
- permissions?: string[];
307
- roles?: string[];
308
- modules?: string[];
309
- fieldOffices?: string[];
310
- requireAll?: boolean;
311
- }
312
295
  /**
313
296
  * Framework-agnostic guard class for endpoint protection
314
297
  */
@@ -480,4 +463,4 @@ declare function createExGuardFastify(config: any): {
480
463
  getGuard(): ExGuardBackend;
481
464
  };
482
465
 
483
- export { type ApiResponse, ExGuardBackend$1 as ExGuardBackend, ExGuardBackendEnhanced, ExGuardCache, type ExGuardCacheConfig, type ExGuardConfig, type ExGuardEnhancedConfig$1 as ExGuardEnhancedConfig, ExGuardRealtime, type ExGuardRealtimeConfig, ExGuardBackend as Guard, type GuardContext$1 as GuardContext, type GuardOptions$1 as GuardOptions, type GuardResult$1 as GuardResult, type UserAccessResponse, cache, createExGuardExpress, createExGuardFastify, realtime };
466
+ export { type ApiResponse, ExGuardBackend$1 as ExGuardBackend, ExGuardBackendEnhanced, ExGuardCache, type ExGuardCacheConfig, type ExGuardConfig, type ExGuardEnhancedConfig$1 as ExGuardEnhancedConfig, ExGuardRealtime, type ExGuardRealtimeConfig, ExGuardBackend as Guard, type GuardContext, type GuardOptions, type GuardResult, type UserAccessResponse, cache, createExGuardExpress, createExGuardFastify, realtime };
package/dist/index.d.ts CHANGED
@@ -51,17 +51,17 @@ interface ExGuardEnhancedConfig$1 extends ExGuardConfig {
51
51
  cache?: ExGuardCacheConfig;
52
52
  realtime?: ExGuardRealtimeConfig;
53
53
  }
54
- interface GuardContext$1 {
54
+ interface GuardContext {
55
55
  token: string;
56
56
  request?: any;
57
57
  }
58
- interface GuardResult$1 {
58
+ interface GuardResult {
59
59
  allowed: boolean;
60
60
  user?: UserAccessResponse;
61
61
  error?: string;
62
62
  statusCode?: number;
63
63
  }
64
- interface GuardOptions$1 {
64
+ interface GuardOptions {
65
65
  permissions?: string[];
66
66
  roles?: string[];
67
67
  modules?: string[];
@@ -292,23 +292,6 @@ declare const realtime: ExGuardRealtime;
292
292
  * Framework-agnostic guards for protecting backend endpoints
293
293
  */
294
294
 
295
- interface GuardContext {
296
- token: string;
297
- request?: any;
298
- }
299
- interface GuardResult {
300
- allowed: boolean;
301
- user?: UserAccessResponse;
302
- error?: string;
303
- statusCode?: number;
304
- }
305
- interface GuardOptions {
306
- permissions?: string[];
307
- roles?: string[];
308
- modules?: string[];
309
- fieldOffices?: string[];
310
- requireAll?: boolean;
311
- }
312
295
  /**
313
296
  * Framework-agnostic guard class for endpoint protection
314
297
  */
@@ -480,4 +463,4 @@ declare function createExGuardFastify(config: any): {
480
463
  getGuard(): ExGuardBackend;
481
464
  };
482
465
 
483
- export { type ApiResponse, ExGuardBackend$1 as ExGuardBackend, ExGuardBackendEnhanced, ExGuardCache, type ExGuardCacheConfig, type ExGuardConfig, type ExGuardEnhancedConfig$1 as ExGuardEnhancedConfig, ExGuardRealtime, type ExGuardRealtimeConfig, ExGuardBackend as Guard, type GuardContext$1 as GuardContext, type GuardOptions$1 as GuardOptions, type GuardResult$1 as GuardResult, type UserAccessResponse, cache, createExGuardExpress, createExGuardFastify, realtime };
466
+ export { type ApiResponse, ExGuardBackend$1 as ExGuardBackend, ExGuardBackendEnhanced, ExGuardCache, type ExGuardCacheConfig, type ExGuardConfig, type ExGuardEnhancedConfig$1 as ExGuardEnhancedConfig, ExGuardRealtime, type ExGuardRealtimeConfig, ExGuardBackend as Guard, type GuardContext, type GuardOptions, type GuardResult, type UserAccessResponse, cache, createExGuardExpress, createExGuardFastify, realtime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exguard-backend",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -46,6 +46,8 @@
46
46
  "test": "node --test",
47
47
  "test:watch": "node --test --watch",
48
48
  "clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\"",
49
- "prebuild": "npm run clean"
49
+ "prebuild": "npm run clean",
50
+ "setup-nestjs": "node scripts/setup-nestjs.js",
51
+ "create-example": "node scripts/create-example.js"
50
52
  }
51
53
  }