@drax/identity-back 0.40.0 → 0.43.0

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.
@@ -1,6 +1,6 @@
1
1
  import { AbstractFastifyController } from "@drax/crud-back";
2
2
  import RegistrationCompleteHtml from "../html/RegistrationCompleteHtml.js";
3
- import { CommonConfig, DraxConfig, StoreManager, ValidationError, UnauthorizedError, SecuritySensitiveError, BadRequestError, } from "@drax/common-back";
3
+ import { CommonConfig, DraxConfig, StoreManager, ValidationError, UnauthorizedError, SecuritySensitiveError, } from "@drax/common-back";
4
4
  import UserServiceFactory from "../factory/UserServiceFactory.js";
5
5
  import RoleServiceFactory from "../factory/RoleServiceFactory.js";
6
6
  import UserPermissions from "../permissions/UserPermissions.js";
@@ -116,13 +116,7 @@ class UserController extends AbstractFastifyController {
116
116
  request.rbac.assertPermission(UserPermissions.SwitchTenant);
117
117
  if (request.authUser && request.token) {
118
118
  const tenantId = request.body.tenantId;
119
- if (!tenantId) {
120
- throw new BadRequestError('Missing tenantId');
121
- }
122
- const tenant = await TenantServiceFactory().findById(tenantId);
123
- if (!tenant) {
124
- throw new BadRequestError('Invalid tenantId');
125
- }
119
+ const tenant = tenantId ? await TenantServiceFactory().findById(tenantId) : undefined;
126
120
  const tenantName = tenant?.name;
127
121
  const userService = UserServiceFactory();
128
122
  let { accessToken } = await userService.switchTenant(request.token, tenantId, tenantName);
@@ -17,10 +17,12 @@ async function rbacMiddleware(request, reply) {
17
17
  const role = await draxCache.getOrLoad(cacheKey, roleLoader);
18
18
  const rbac = new Rbac(authUser, role);
19
19
  request.rbac = rbac;
20
+ reply.rbac = rbac;
20
21
  }
21
22
  else {
22
23
  const rbac = new Rbac(null, null);
23
24
  request.rbac = rbac;
25
+ reply.rbac = rbac;
24
26
  }
25
27
  return;
26
28
  }
@@ -50,7 +50,7 @@ async function UserAvatarRoutes(fastify, options) {
50
50
  const filename = request.params.filename;
51
51
  const subPath = 'avatar';
52
52
  const fileDir = join(BASE_FILE_DIR, subPath);
53
- console.log("FILE_DIR: ", fileDir, " FILENAME:", filename);
53
+ //console.log("FILE_DIR: ", fileDir, " FILENAME:", filename);
54
54
  return reply.sendFile(filename, fileDir);
55
55
  }
56
56
  catch (e) {
@@ -6,7 +6,6 @@ class RoleService extends AbstractService {
6
6
  constructor(roleRepostitory) {
7
7
  super(roleRepostitory, RoleBaseSchema);
8
8
  this._repository = roleRepostitory;
9
- console.log("RoleService constructor");
10
9
  }
11
10
  async create(roleData) {
12
11
  try {
@@ -6,7 +6,6 @@ class TenantService extends AbstractService {
6
6
  constructor(tenantRepostitory) {
7
7
  super(tenantRepostitory, TenantBaseSchema);
8
8
  this._repository = tenantRepostitory;
9
- console.log("TenantService constructor");
10
9
  }
11
10
  async create(tenantData) {
12
11
  try {
@@ -9,7 +9,6 @@ class UserApiKeyService extends AbstractService {
9
9
  constructor(userApiKeyRepostitory) {
10
10
  super(userApiKeyRepostitory, UserApiKeyBaseSchema);
11
11
  this._repository = userApiKeyRepostitory;
12
- console.log("UserApiKeyService constructor");
13
12
  }
14
13
  async create(userApiKeyData) {
15
14
  try {
@@ -11,7 +11,6 @@ class UserService extends AbstractService {
11
11
  constructor(userRepository) {
12
12
  super(userRepository, UserBaseSchema);
13
13
  this._repository = userRepository;
14
- console.log("UserService constructor");
15
14
  }
16
15
  async auth(username, password, { userAgent, ip }) {
17
16
  let user = null;
@@ -15,7 +15,6 @@ async function CreateOrUpdateRole(roleData) {
15
15
  }));
16
16
  }
17
17
  if (role) {
18
- console.log("RoleData", roleData);
19
18
  const r = await roleService.systemUpdate(role._id.toString(), roleData);
20
19
  console.log("Role Updated. Name: " + roleData.name);
21
20
  return r;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.40.0",
6
+ "version": "0.43.0",
7
7
  "description": "Identity module for user management, authentication and authorization.",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -28,11 +28,11 @@
28
28
  "author": "Cristian Incarnato & Drax Team",
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
- "@drax/common-back": "^0.40.0",
32
- "@drax/crud-back": "^0.40.0",
33
- "@drax/crud-share": "^0.40.0",
34
- "@drax/email-back": "^0.40.0",
35
- "@drax/identity-share": "^0.40.0",
31
+ "@drax/common-back": "^0.43.0",
32
+ "@drax/crud-back": "^0.43.0",
33
+ "@drax/crud-share": "^0.43.0",
34
+ "@drax/email-back": "^0.43.0",
35
+ "@drax/identity-share": "^0.43.0",
36
36
  "bcryptjs": "^2.4.3",
37
37
  "graphql": "^16.8.2",
38
38
  "jsonwebtoken": "^9.0.2"
@@ -63,5 +63,5 @@
63
63
  "debug": "0"
64
64
  }
65
65
  },
66
- "gitHead": "269ec7921d83364dfba091cd74bd3f45a8135c26"
66
+ "gitHead": "3451a1c66eaf3facd4fef67d96750bf5d38a1d5c"
67
67
  }
@@ -141,15 +141,9 @@ class UserController extends AbstractFastifyController<IUser, IUserCreate, IUser
141
141
 
142
142
  if (request.authUser && request.token) {
143
143
  const tenantId = request.body.tenantId
144
- if (!tenantId) {
145
- throw new BadRequestError('Missing tenantId')
146
- }
147
144
 
148
- const tenant = await TenantServiceFactory().findById(tenantId);
149
145
 
150
- if (!tenant) {
151
- throw new BadRequestError('Invalid tenantId')
152
- }
146
+ const tenant = tenantId ? await TenantServiceFactory().findById(tenantId) : undefined;
153
147
 
154
148
  const tenantName = tenant?.name;
155
149
  const userService = UserServiceFactory()
@@ -22,9 +22,11 @@ async function rbacMiddleware (request, reply) {
22
22
  const role : IRole = await draxCache.getOrLoad(cacheKey, roleLoader)
23
23
  const rbac: IRbac = new Rbac(authUser,role)
24
24
  request.rbac = rbac
25
+ reply.rbac = rbac
25
26
  }else{
26
27
  const rbac: IRbac = new Rbac(null,null)
27
28
  request.rbac = rbac
29
+ reply.rbac = rbac
28
30
  }
29
31
  return
30
32
  }catch (e) {
@@ -13,7 +13,6 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
13
13
  constructor(roleRepostitory: IRoleRepository) {
14
14
  super(roleRepostitory, RoleBaseSchema)
15
15
  this._repository = roleRepostitory
16
- console.log("RoleService constructor")
17
16
  }
18
17
 
19
18
  async create(roleData: IRoleBase): Promise<IRole> {
@@ -13,7 +13,6 @@ class TenantService extends AbstractService<ITenant,ITenantBase,ITenantBase> {
13
13
  constructor(tenantRepostitory: ITenantRepository) {
14
14
  super(tenantRepostitory, TenantBaseSchema)
15
15
  this._repository = tenantRepostitory
16
- console.log("TenantService constructor")
17
16
  }
18
17
 
19
18
  async create(tenantData: ITenantBase): Promise<ITenant> {
@@ -16,7 +16,6 @@ class UserApiKeyService extends AbstractService<IUserApiKey, IUserApiKeyBase, IU
16
16
  constructor(userApiKeyRepostitory: IUserApiKeyRepository) {
17
17
  super(userApiKeyRepostitory,UserApiKeyBaseSchema)
18
18
  this._repository = userApiKeyRepostitory
19
- console.log("UserApiKeyService constructor")
20
19
  }
21
20
 
22
21
  async create(userApiKeyData: IUserApiKeyBase): Promise<IUserApiKey> {
@@ -19,7 +19,6 @@ class UserService extends AbstractService<IUser, IUserCreate, IUserUpdate> {
19
19
  constructor(userRepository: IUserRepository) {
20
20
  super(userRepository, UserBaseSchema);
21
21
  this._repository = userRepository;
22
- console.log("UserService constructor")
23
22
  }
24
23
 
25
24
  async auth(username: string, password: string, {userAgent, ip}) {
@@ -18,7 +18,6 @@ async function CreateOrUpdateRole(roleData: IRoleBase):Promise<IRole> {
18
18
  }
19
19
 
20
20
  if(role){
21
- console.log("RoleData",roleData)
22
21
  const r = await roleService.systemUpdate(role._id.toString(), roleData)
23
22
  console.log("Role Updated. Name: "+ roleData.name)
24
23
  return r