@punks/backend-entity-manager 0.0.180 → 0.0.182
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 +36 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/decorators/guards.d.ts +4 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/decorators/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/types/index.d.ts +4 -0
- package/dist/esm/index.js +35 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/decorators/guards.d.ts +4 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/decorators/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/guards/auth.d.ts +2 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/types/index.d.ts +4 -0
- package/dist/index.d.ts +11 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2532,11 +2532,13 @@ const AuthenticationGuardsSymbols = {
|
|
|
2532
2532
|
|
|
2533
2533
|
const Public = () => common.SetMetadata(AuthenticationGuardsSymbols.Public, true);
|
|
2534
2534
|
const Authenticated = () => common.SetMetadata(AuthenticationGuardsSymbols.Authenticated, true);
|
|
2535
|
+
const Permissions = (...permissions) => common.SetMetadata(AuthenticationGuardsSymbols.Permissions, permissions);
|
|
2535
2536
|
const Roles = (...roles) => common.SetMetadata(AuthenticationGuardsSymbols.Roles, roles);
|
|
2536
2537
|
const MemberOf = (...groups) => common.SetMetadata(AuthenticationGuardsSymbols.MemberOf, groups);
|
|
2537
2538
|
const buildRolesGuard = ({ mainRole, secondaryRoles, }, options) => Roles(mainRole.uid, ...(!options?.exact && secondaryRoles
|
|
2538
2539
|
? secondaryRoles.map((role) => role.uid)
|
|
2539
2540
|
: []));
|
|
2541
|
+
const buildPermissionsGuard = ({ permissions, }) => Permissions(...permissions.map((x) => x.uid));
|
|
2540
2542
|
|
|
2541
2543
|
const WpPermissionsService = () => common.applyDecorators(common.Injectable(), common.SetMetadata(AuthenticationExtensionSymbols.PermissionsService, true));
|
|
2542
2544
|
|
|
@@ -2629,15 +2631,34 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2629
2631
|
const allowedRoles = this.getAllowedRoles(context);
|
|
2630
2632
|
if (allowedRoles) {
|
|
2631
2633
|
const isAllowed = this.isRoleMatching(allowedRoles, auth?.roles ?? []);
|
|
2632
|
-
this.logger.debug(`Authorized:${isAllowed} -> authorization guard`, {
|
|
2634
|
+
this.logger.debug(`Authorized:${isAllowed} -> authorization role guard`, {
|
|
2633
2635
|
...this.getContextInfo({
|
|
2634
2636
|
context,
|
|
2635
2637
|
roles: auth?.roles,
|
|
2636
2638
|
user: auth?.user,
|
|
2639
|
+
permissions: auth?.permissions,
|
|
2637
2640
|
}),
|
|
2638
2641
|
allowedRoles,
|
|
2639
2642
|
});
|
|
2640
|
-
|
|
2643
|
+
if (!isAllowed) {
|
|
2644
|
+
return false;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
const allowedPermissions = this.getAllowedPermissions(context);
|
|
2648
|
+
if (allowedPermissions) {
|
|
2649
|
+
const isAllowed = this.isPermissionMatching(allowedPermissions, auth?.roles ?? []);
|
|
2650
|
+
this.logger.debug(`Authorized:${isAllowed} -> authorization permission guard`, {
|
|
2651
|
+
...this.getContextInfo({
|
|
2652
|
+
context,
|
|
2653
|
+
roles: auth?.roles,
|
|
2654
|
+
user: auth?.user,
|
|
2655
|
+
permissions: auth?.permissions,
|
|
2656
|
+
}),
|
|
2657
|
+
allowedPermissions,
|
|
2658
|
+
});
|
|
2659
|
+
if (!isAllowed) {
|
|
2660
|
+
return false;
|
|
2661
|
+
}
|
|
2641
2662
|
}
|
|
2642
2663
|
const isForAllAuthenticated = this.getIsForAllAuthenticated(context);
|
|
2643
2664
|
if (isForAllAuthenticated) {
|
|
@@ -2647,6 +2668,7 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2647
2668
|
context,
|
|
2648
2669
|
roles: auth?.roles,
|
|
2649
2670
|
user: auth?.user,
|
|
2671
|
+
permissions: auth?.permissions,
|
|
2650
2672
|
}),
|
|
2651
2673
|
});
|
|
2652
2674
|
return isAuthenticated;
|
|
@@ -2657,6 +2679,7 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2657
2679
|
context,
|
|
2658
2680
|
roles: auth?.roles,
|
|
2659
2681
|
user: auth?.user,
|
|
2682
|
+
permissions: auth?.permissions,
|
|
2660
2683
|
}),
|
|
2661
2684
|
});
|
|
2662
2685
|
return isAuthenticated;
|
|
@@ -2664,6 +2687,9 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2664
2687
|
isRoleMatching(allowedRoles, userRoles) {
|
|
2665
2688
|
return userRoles.some((role) => allowedRoles.includes(role.uid));
|
|
2666
2689
|
}
|
|
2690
|
+
isPermissionMatching(allowedPermissions, userPermissions) {
|
|
2691
|
+
return userPermissions.some((permission) => allowedPermissions.includes(permission.uid));
|
|
2692
|
+
}
|
|
2667
2693
|
getIsForAllAuthenticated(context) {
|
|
2668
2694
|
return this.getMetadata(AuthenticationGuardsSymbols.Authenticated, context);
|
|
2669
2695
|
}
|
|
@@ -2673,12 +2699,16 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2673
2699
|
getAllowedRoles(context) {
|
|
2674
2700
|
return this.getMetadata(AuthenticationGuardsSymbols.Roles, context);
|
|
2675
2701
|
}
|
|
2702
|
+
getAllowedPermissions(context) {
|
|
2703
|
+
return this.getMetadata(AuthenticationGuardsSymbols.Permissions, context);
|
|
2704
|
+
}
|
|
2676
2705
|
getCurrentAuth(context) {
|
|
2677
2706
|
const request = context.switchToHttp()?.getRequest();
|
|
2678
2707
|
return request?.auth?.user
|
|
2679
2708
|
? {
|
|
2680
2709
|
user: request.auth.user,
|
|
2681
2710
|
roles: request.auth.roles,
|
|
2711
|
+
permissions: request.auth.permissions,
|
|
2682
2712
|
}
|
|
2683
2713
|
: undefined;
|
|
2684
2714
|
}
|
|
@@ -2688,7 +2718,7 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2688
2718
|
context.getClass(),
|
|
2689
2719
|
]);
|
|
2690
2720
|
}
|
|
2691
|
-
getContextInfo({ context, user, roles, }) {
|
|
2721
|
+
getContextInfo({ context, user, roles, permissions, }) {
|
|
2692
2722
|
return {
|
|
2693
2723
|
request: {
|
|
2694
2724
|
path: context.switchToHttp()?.getRequest()?.path,
|
|
@@ -2701,6 +2731,7 @@ exports.AuthGuard = AuthGuard_1 = class AuthGuard {
|
|
|
2701
2731
|
userName: user.userName,
|
|
2702
2732
|
email: user.email,
|
|
2703
2733
|
roles: roles?.map((role) => role.uid),
|
|
2734
|
+
permissions: permissions?.map((permission) => permission.uid),
|
|
2704
2735
|
},
|
|
2705
2736
|
}
|
|
2706
2737
|
: {}),
|
|
@@ -28413,6 +28444,7 @@ exports.NestTypeOrmQueryBuilder = NestTypeOrmQueryBuilder;
|
|
|
28413
28444
|
exports.NestTypeOrmRepository = NestTypeOrmRepository;
|
|
28414
28445
|
exports.OperationTokenMismatchError = OperationTokenMismatchError;
|
|
28415
28446
|
exports.PLATFORM_EVENT_NAMESPACE = PLATFORM_EVENT_NAMESPACE;
|
|
28447
|
+
exports.Permissions = Permissions;
|
|
28416
28448
|
exports.PipelineController = PipelineController;
|
|
28417
28449
|
exports.PipelineInvocationError = PipelineInvocationError;
|
|
28418
28450
|
exports.PlatformEvents = PlatformEvents;
|
|
@@ -28448,6 +28480,7 @@ exports.WpRolesService = WpRolesService;
|
|
|
28448
28480
|
exports.WpSendgridEmailTemplate = WpSendgridEmailTemplate;
|
|
28449
28481
|
exports.WpUserRolesService = WpUserRolesService;
|
|
28450
28482
|
exports.WpUserService = WpUserService;
|
|
28483
|
+
exports.buildPermissionsGuard = buildPermissionsGuard;
|
|
28451
28484
|
exports.buildRolesGuard = buildRolesGuard;
|
|
28452
28485
|
exports.createContainer = createContainer;
|
|
28453
28486
|
exports.createExpressFileResponse = createExpressFileResponse;
|