@punks/backend-entity-manager 0.0.108 → 0.0.109
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 +53 -4
- 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 +53 -4
- 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,24 +2402,53 @@ 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
|
-
|
|
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;
|
|
2422
2444
|
}
|
|
2445
|
+
this.logger.debug(`Authorized:false -> auth guard`, {
|
|
2446
|
+
...this.getContextInfo({
|
|
2447
|
+
context,
|
|
2448
|
+
roles: auth?.roles,
|
|
2449
|
+
user: auth?.user,
|
|
2450
|
+
}),
|
|
2451
|
+
});
|
|
2423
2452
|
return false;
|
|
2424
2453
|
}
|
|
2425
2454
|
isRoleMatching(allowedRoles, userRoles) {
|
|
@@ -2449,8 +2478,28 @@ exports.AuthGuard = class AuthGuard {
|
|
|
2449
2478
|
context.getClass(),
|
|
2450
2479
|
]);
|
|
2451
2480
|
}
|
|
2481
|
+
getContextInfo({ context, user, roles, }) {
|
|
2482
|
+
return {
|
|
2483
|
+
request: {
|
|
2484
|
+
path: context.switchToHttp()?.getRequest()?.path,
|
|
2485
|
+
method: context.switchToHttp()?.getRequest()?.method,
|
|
2486
|
+
},
|
|
2487
|
+
...(user
|
|
2488
|
+
? {
|
|
2489
|
+
id: user.id,
|
|
2490
|
+
userName: user.userName,
|
|
2491
|
+
email: user.email,
|
|
2492
|
+
roles: roles?.map((role) => ({
|
|
2493
|
+
id: role.id,
|
|
2494
|
+
name: role.name,
|
|
2495
|
+
uid: role.uid,
|
|
2496
|
+
})),
|
|
2497
|
+
}
|
|
2498
|
+
: {}),
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2452
2501
|
};
|
|
2453
|
-
exports.AuthGuard = __decorate([
|
|
2502
|
+
exports.AuthGuard = AuthGuard_1 = __decorate([
|
|
2454
2503
|
common.Injectable(),
|
|
2455
2504
|
__metadata("design:paramtypes", [core.Reflector])
|
|
2456
2505
|
], exports.AuthGuard);
|