exguard-backend 1.0.17 → 1.0.18
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 +17 -8
- package/package.json +1 -1
- package/scripts/setup-nestjs.cjs +45 -2
package/README.md
CHANGED
|
@@ -31,19 +31,28 @@ pnpm add exguard-backend
|
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
33
|
# Install exguard-backend
|
|
34
|
-
npm install exguard-backend@1.0.
|
|
34
|
+
npm install exguard-backend@1.0.17
|
|
35
35
|
|
|
36
|
-
# Run automatic setup
|
|
37
|
-
npx exguard-backend@1.0.
|
|
36
|
+
# Run automatic setup (overwrites existing files)
|
|
37
|
+
npx exguard-backend@1.0.17
|
|
38
38
|
# OR
|
|
39
39
|
npm run setup-nestjs
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
**Quick Start - NestJS Integration:**
|
|
43
|
+
|
|
44
|
+
After running the setup script, you can quickly start using ExGuard:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Start development server
|
|
48
|
+
npm run start:dev
|
|
49
|
+
|
|
50
|
+
# The setup script automatically:
|
|
51
|
+
# ✅ Creates src/exguard/ directory with all guards and decorators
|
|
52
|
+
# ✅ Updates src/app.module.ts with ExGuardModule import
|
|
53
|
+
# ✅ Creates src/events/events.controller.ts with working examples
|
|
54
|
+
# ✅ Adds npm scripts for easy access
|
|
55
|
+
```
|
|
47
56
|
✅ **Improved module detection** - More reliable NestJS project detection
|
|
48
57
|
✅ **Enhanced file creation** - Better file path handling
|
|
49
58
|
✅ **TypeScript error fixes** - All generated code is type-safe
|
package/package.json
CHANGED
package/scripts/setup-nestjs.cjs
CHANGED
|
@@ -226,24 +226,40 @@ export class ExGuardRoleGuard extends ExGuardNestGuard {
|
|
|
226
226
|
export function createPermissionGuard(permissions: string[], requireAll = false) {
|
|
227
227
|
return class extends ExGuardNestGuard {
|
|
228
228
|
public async checkPermissions(context: GuardContext) {
|
|
229
|
+
console.log('🔍 DEBUG: Permission guard called');
|
|
230
|
+
console.log('🔍 DEBUG: Required permissions:', permissions);
|
|
231
|
+
console.log('🔍 DEBUG: Require all:', requireAll);
|
|
232
|
+
|
|
229
233
|
// First authenticate the user
|
|
230
234
|
const authResult = await this.exGuard.authenticate(context);
|
|
231
235
|
|
|
236
|
+
console.log('🔍 DEBUG: Auth result:', {
|
|
237
|
+
allowed: authResult.allowed,
|
|
238
|
+
hasUser: !!authResult.user,
|
|
239
|
+
error: authResult.error
|
|
240
|
+
});
|
|
241
|
+
|
|
232
242
|
if (!authResult.allowed) {
|
|
243
|
+
console.log('🔍 DEBUG: Authentication failed');
|
|
233
244
|
return authResult;
|
|
234
245
|
}
|
|
235
246
|
|
|
236
247
|
// Then check specific permissions
|
|
237
248
|
// Extract permissions from modules array
|
|
238
249
|
if (!authResult.user) {
|
|
250
|
+
console.log('🔍 DEBUG: No user found in auth result');
|
|
239
251
|
return { allowed: false, error: 'User not found in authentication result' };
|
|
240
252
|
}
|
|
253
|
+
|
|
241
254
|
const userPermissions = authResult.user.modules?.flatMap(module => module.permissions) || [];
|
|
255
|
+
console.log('🔍 DEBUG: User permissions:', userPermissions);
|
|
242
256
|
|
|
243
257
|
if (requireAll) {
|
|
244
258
|
// User must have ALL permissions
|
|
245
259
|
const hasAllPermissions = permissions.every(perm => userPermissions.includes(perm));
|
|
260
|
+
console.log('🔍 DEBUG: Has all permissions check:', hasAllPermissions);
|
|
246
261
|
if (!hasAllPermissions) {
|
|
262
|
+
console.log('🔍 DEBUG: Missing required permissions (ALL)');
|
|
247
263
|
return {
|
|
248
264
|
allowed: false,
|
|
249
265
|
error: 'Insufficient permissions. Required all of: ' + permissions.join(', ')
|
|
@@ -252,7 +268,9 @@ export function createPermissionGuard(permissions: string[], requireAll = false)
|
|
|
252
268
|
} else {
|
|
253
269
|
// User must have ANY permission
|
|
254
270
|
const hasAnyPermission = permissions.some(perm => userPermissions.includes(perm));
|
|
271
|
+
console.log('🔍 DEBUG: Has any permission check:', hasAnyPermission);
|
|
255
272
|
if (!hasAnyPermission) {
|
|
273
|
+
console.log('🔍 DEBUG: Missing required permissions (ANY)');
|
|
256
274
|
return {
|
|
257
275
|
allowed: false,
|
|
258
276
|
error: 'Insufficient permissions. Required any of: ' + permissions.join(', ')
|
|
@@ -260,6 +278,7 @@ export function createPermissionGuard(permissions: string[], requireAll = false)
|
|
|
260
278
|
}
|
|
261
279
|
}
|
|
262
280
|
|
|
281
|
+
console.log('🔍 DEBUG: Permission check passed');
|
|
263
282
|
return {
|
|
264
283
|
allowed: true,
|
|
265
284
|
user: authResult.user
|
|
@@ -460,6 +479,13 @@ export class EventsController {
|
|
|
460
479
|
}
|
|
461
480
|
`;
|
|
462
481
|
|
|
482
|
+
// Ensure directory exists
|
|
483
|
+
const eventsDir = path.join(process.cwd(), 'src/events');
|
|
484
|
+
if (!fs.existsSync(eventsDir)) {
|
|
485
|
+
fs.mkdirSync(eventsDir, { recursive: true });
|
|
486
|
+
logSuccess('Created events directory');
|
|
487
|
+
}
|
|
488
|
+
|
|
463
489
|
const controllerPath = path.join(process.cwd(), 'src/events/events.controller.ts');
|
|
464
490
|
|
|
465
491
|
if (fs.existsSync(controllerPath)) {
|
|
@@ -477,7 +503,23 @@ function updateAppModule() {
|
|
|
477
503
|
const appModulePath = path.join(process.cwd(), 'src/app.module.ts');
|
|
478
504
|
|
|
479
505
|
if (!fs.existsSync(appModulePath)) {
|
|
480
|
-
logWarning('app.module.ts not found.
|
|
506
|
+
logWarning('app.module.ts not found. Creating basic app.module.ts...');
|
|
507
|
+
|
|
508
|
+
// Create basic app.module.ts
|
|
509
|
+
const basicAppModule = `import { Module } from '@nestjs/common';
|
|
510
|
+
import { ExGuardModule } from './exguard/exguard.module';
|
|
511
|
+
|
|
512
|
+
@Module({
|
|
513
|
+
imports: [
|
|
514
|
+
ExGuardModule
|
|
515
|
+
],
|
|
516
|
+
controllers: [],
|
|
517
|
+
})
|
|
518
|
+
export class AppModule {}
|
|
519
|
+
`;
|
|
520
|
+
|
|
521
|
+
fs.writeFileSync(appModulePath, basicAppModule);
|
|
522
|
+
logSuccess('Created basic app.module.ts with ExGuardModule');
|
|
481
523
|
return;
|
|
482
524
|
}
|
|
483
525
|
|
|
@@ -580,7 +622,8 @@ function updatePackageScripts() {
|
|
|
580
622
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
581
623
|
|
|
582
624
|
const scriptsToAdd = {
|
|
583
|
-
'
|
|
625
|
+
'setup-nestjs': 'node node_modules/exguard-backend/scripts/setup-nestjs.cjs',
|
|
626
|
+
'exguard:setup': 'node node_modules/exguard-backend/scripts/setup-nestjs.cjs',
|
|
584
627
|
'exguard:example': 'node node_modules/exguard-backend/scripts/create-example.cjs'
|
|
585
628
|
};
|
|
586
629
|
|