@punks/backend-entity-manager 0.0.108 → 0.0.110
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/dist/cjs/index.js +58 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/__test__/server/entities/crmContacts/crmContact.query.d.ts +1 -2
- package/dist/cjs/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/esm/index.js +58 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/__test__/server/entities/crmContacts/crmContact.query.d.ts +1 -2
- package/dist/esm/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2402,25 +2402,55 @@ const AuthenticationEvents = {
|
|
|
2402
2402
|
UserPasswordResetCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetCompleted`,
|
|
2403
2403
|
};
|
|
2404
2404
|
|
|
2405
|
-
|
|
2405
|
+
var AuthGuard_1;
|
|
2406
|
+
exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
2406
2407
|
constructor(reflector) {
|
|
2407
2408
|
this.reflector = reflector;
|
|
2409
|
+
this.logger = backendCore.Log.getLogger(AuthGuard_1.name);
|
|
2408
2410
|
}
|
|
2409
2411
|
canActivate(context) {
|
|
2410
2412
|
const isPublic = this.getIsPublic(context);
|
|
2411
2413
|
if (isPublic) {
|
|
2414
|
+
this.logger.debug(`Authorized:true -> public route`, this.getContextInfo({
|
|
2415
|
+
context,
|
|
2416
|
+
}));
|
|
2412
2417
|
return true;
|
|
2413
2418
|
}
|
|
2414
2419
|
const auth = this.getCurrentAuth(context);
|
|
2415
2420
|
const allowedRoles = this.getAllowedRoles(context);
|
|
2416
2421
|
if (allowedRoles) {
|
|
2417
|
-
|
|
2422
|
+
const isAllowed = this.isRoleMatching(allowedRoles, auth?.roles ?? []);
|
|
2423
|
+
this.logger.debug(`Authorized:${isAllowed} -> authorization guard`, {
|
|
2424
|
+
...this.getContextInfo({
|
|
2425
|
+
context,
|
|
2426
|
+
roles: auth?.roles,
|
|
2427
|
+
user: auth?.user,
|
|
2428
|
+
}),
|
|
2429
|
+
allowedRoles,
|
|
2430
|
+
});
|
|
2431
|
+
return isAllowed;
|
|
2418
2432
|
}
|
|
2419
2433
|
const isForAllAuthenticated = this.getIsForAllAuthenticated(context);
|
|
2420
2434
|
if (isForAllAuthenticated) {
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2435
|
+
const isAuthenticated = !!auth?.user;
|
|
2436
|
+
this.logger.debug(`Authorized:${isAuthenticated} -> authentication guard`, {
|
|
2437
|
+
...this.getContextInfo({
|
|
2438
|
+
context,
|
|
2439
|
+
roles: auth?.roles,
|
|
2440
|
+
user: auth?.user,
|
|
2441
|
+
}),
|
|
2442
|
+
});
|
|
2443
|
+
return isAuthenticated;
|
|
2444
|
+
}
|
|
2445
|
+
const isAuthenticated = !!auth?.user;
|
|
2446
|
+
this.logger.debug(`Authorized:${isAuthenticated} -> auth guard`, {
|
|
2447
|
+
...this.getContextInfo({
|
|
2448
|
+
context,
|
|
2449
|
+
roles: auth?.roles,
|
|
2450
|
+
user: auth?.user,
|
|
2451
|
+
}),
|
|
2452
|
+
});
|
|
2453
|
+
return isAuthenticated;
|
|
2424
2454
|
}
|
|
2425
2455
|
isRoleMatching(allowedRoles, userRoles) {
|
|
2426
2456
|
return userRoles.some((role) => allowedRoles.includes(role.uid));
|
|
@@ -2449,8 +2479,30 @@ exports.AuthGuard = class AuthGuard {
|
|
|
2449
2479
|
context.getClass(),
|
|
2450
2480
|
]);
|
|
2451
2481
|
}
|
|
2482
|
+
getContextInfo({ context, user, roles, }) {
|
|
2483
|
+
return {
|
|
2484
|
+
request: {
|
|
2485
|
+
path: context.switchToHttp()?.getRequest()?.path,
|
|
2486
|
+
method: context.switchToHttp()?.getRequest()?.method,
|
|
2487
|
+
},
|
|
2488
|
+
...(user
|
|
2489
|
+
? {
|
|
2490
|
+
user: {
|
|
2491
|
+
id: user.id,
|
|
2492
|
+
userName: user.userName,
|
|
2493
|
+
email: user.email,
|
|
2494
|
+
roles: roles?.map((role) => ({
|
|
2495
|
+
id: role.id,
|
|
2496
|
+
name: role.name,
|
|
2497
|
+
uid: role.uid,
|
|
2498
|
+
})),
|
|
2499
|
+
},
|
|
2500
|
+
}
|
|
2501
|
+
: {}),
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2452
2504
|
};
|
|
2453
|
-
exports.AuthGuard = __decorate([
|
|
2505
|
+
exports.AuthGuard = AuthGuard_1 = __decorate([
|
|
2454
2506
|
common.Injectable(),
|
|
2455
2507
|
__metadata("design:paramtypes", [core.Reflector])
|
|
2456
2508
|
], exports.AuthGuard);
|