@drax/identity-back 0.33.1 → 0.34.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.
- package/dist/config/IdentityConfig.js +0 -0
- package/dist/controllers/RoleController.js +0 -0
- package/dist/controllers/TenantController.js +0 -0
- package/dist/controllers/UserApiKeyController.js +0 -0
- package/dist/controllers/UserController.js +1 -1
- package/dist/errors/BadCredentialsError.js +0 -0
- package/dist/factory/RoleServiceFactory.js +0 -0
- package/dist/factory/TenantServiceFactory.js +0 -0
- package/dist/factory/UserApiKeyServiceFactory.js +0 -0
- package/dist/factory/UserRegistryServiceFactory.js +24 -0
- package/dist/factory/UserServiceFactory.js +0 -0
- package/dist/graphql/index.js +0 -0
- package/dist/graphql/resolvers/role.resolvers.js +0 -0
- package/dist/graphql/resolvers/tenant.resolvers.js +0 -0
- package/dist/graphql/resolvers/user-api-key.resolvers.js +0 -0
- package/dist/graphql/resolvers/user.resolvers.js +0 -0
- package/dist/index.js +0 -0
- package/dist/interfaces/IRbac.js +1 -0
- package/dist/interfaces/IRoleRepository.js +0 -0
- package/dist/interfaces/ITenantRepository.js +0 -0
- package/dist/interfaces/IUserApiKeyRepository.js +0 -0
- package/dist/interfaces/IUserRepository.js +0 -0
- package/dist/middleware/apiKeyMiddleware.js +0 -0
- package/dist/middleware/jwtMiddleware.js +0 -0
- package/dist/middleware/rbacMiddleware.js +0 -0
- package/dist/models/RoleModel.js +0 -0
- package/dist/models/TenantModel.js +0 -0
- package/dist/models/UserApiKeyModel.js +0 -0
- package/dist/models/UserGroupModel.js +0 -0
- package/dist/models/UserModel.js +0 -0
- package/dist/permissions/IdentityPermissions.js +0 -0
- package/dist/permissions/RolePermissions.js +0 -0
- package/dist/permissions/TenantPermissions.js +0 -0
- package/dist/permissions/UserApiKeyPermissions.js +0 -0
- package/dist/permissions/UserPermissions.js +0 -0
- package/dist/permissions/index.js +0 -0
- package/dist/rbac/Rbac.js +0 -0
- package/dist/repository/mongo/RoleMongoRepository.js +0 -0
- package/dist/repository/mongo/TenantMongoRepository.js +0 -0
- package/dist/repository/mongo/UserApiKeyMongoRepository.js +0 -0
- package/dist/repository/mongo/UserMongoRepository.js +0 -0
- package/dist/repository/sqlite/RoleSqliteRepository.js +0 -0
- package/dist/repository/sqlite/TenantSqliteRepository.js +0 -0
- package/dist/repository/sqlite/UserApiKeySqliteRepository.js +0 -0
- package/dist/repository/sqlite/UserSqliteRepository.js +0 -0
- package/dist/routes/RoleRoutes.js +0 -0
- package/dist/routes/TenantRoutes.js +0 -0
- package/dist/routes/UserApiKeyRoutes.js +0 -0
- package/dist/routes/UserAvatarRoutes.js +70 -0
- package/dist/routes/UserRoutes.js +0 -0
- package/dist/schemas/TenantSchema.js +1 -1
- package/dist/services/PermissionService.js +0 -0
- package/dist/services/RoleService.js +0 -0
- package/dist/services/TenantService.js +0 -0
- package/dist/services/UserApiKeyService.js +0 -0
- package/dist/services/UserService.js +0 -0
- package/dist/setup/CreateOrUpdateRole.js +0 -0
- package/dist/setup/CreateUserIfNotExist.js +0 -0
- package/dist/setup/LoadIdentityConfigFromEnv.js +0 -0
- package/dist/setup/LoadPermissions.js +0 -0
- package/dist/setup/RecoveryUserPassword.js +0 -0
- package/dist/utils/AuthUtils.js +0 -0
- package/dist/zod/EndpointZod.js +9 -0
- package/dist/zod/RoleZod.js +8 -0
- package/dist/zod/TenantSchema.js +12 -0
- package/dist/zod/TenantZod.js +10 -0
- package/dist/zod/UserApiKeyZod.js +13 -0
- package/dist/zod/UserZod.js +18 -0
- package/package.json +7 -7
- package/src/controllers/UserController.ts +1 -1
- package/src/schemas/TenantSchema.ts +1 -1
- package/test.db +0 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/config/IdentityConfig.d.ts +0 -0
- package/types/config/IdentityConfig.d.ts.map +0 -0
- package/types/controllers/RoleController.d.ts +0 -0
- package/types/controllers/RoleController.d.ts.map +0 -0
- package/types/controllers/TenantController.d.ts +0 -0
- package/types/controllers/TenantController.d.ts.map +0 -0
- package/types/controllers/UserApiKeyController.d.ts +0 -0
- package/types/controllers/UserApiKeyController.d.ts.map +0 -0
- package/types/controllers/UserController.d.ts +0 -0
- package/types/controllers/UserController.d.ts.map +0 -0
- package/types/errors/BadCredentialsError.d.ts +0 -0
- package/types/errors/BadCredentialsError.d.ts.map +0 -0
- package/types/factory/RoleServiceFactory.d.ts +0 -0
- package/types/factory/RoleServiceFactory.d.ts.map +0 -0
- package/types/factory/TenantServiceFactory.d.ts +0 -0
- package/types/factory/TenantServiceFactory.d.ts.map +0 -0
- package/types/factory/UserApiKeyServiceFactory.d.ts +1 -1
- package/types/factory/UserApiKeyServiceFactory.d.ts.map +0 -0
- package/types/factory/UserRegistryServiceFactory.d.ts +4 -0
- package/types/factory/UserRegistryServiceFactory.d.ts.map +1 -0
- package/types/factory/UserServiceFactory.d.ts +0 -0
- package/types/factory/UserServiceFactory.d.ts.map +0 -0
- package/types/graphql/index.d.ts +0 -0
- package/types/graphql/index.d.ts.map +0 -0
- package/types/graphql/resolvers/role.resolvers.d.ts +0 -0
- package/types/graphql/resolvers/role.resolvers.d.ts.map +0 -0
- package/types/graphql/resolvers/tenant.resolvers.d.ts +0 -0
- package/types/graphql/resolvers/tenant.resolvers.d.ts.map +0 -0
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts +0 -0
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts.map +0 -0
- package/types/graphql/resolvers/user.resolvers.d.ts +0 -0
- package/types/graphql/resolvers/user.resolvers.d.ts.map +0 -0
- package/types/index.d.ts +0 -0
- package/types/index.d.ts.map +0 -0
- package/types/interfaces/IRbac.d.ts +16 -0
- package/types/interfaces/IRbac.d.ts.map +1 -0
- package/types/interfaces/IRoleRepository.d.ts +0 -0
- package/types/interfaces/IRoleRepository.d.ts.map +0 -0
- package/types/interfaces/ITenantRepository.d.ts +0 -0
- package/types/interfaces/ITenantRepository.d.ts.map +0 -0
- package/types/interfaces/IUserApiKeyRepository.d.ts +0 -0
- package/types/interfaces/IUserApiKeyRepository.d.ts.map +0 -0
- package/types/interfaces/IUserRepository.d.ts +0 -0
- package/types/interfaces/IUserRepository.d.ts.map +0 -0
- package/types/middleware/apiKeyMiddleware.d.ts +0 -0
- package/types/middleware/apiKeyMiddleware.d.ts.map +0 -0
- package/types/middleware/jwtMiddleware.d.ts +0 -0
- package/types/middleware/jwtMiddleware.d.ts.map +0 -0
- package/types/middleware/rbacMiddleware.d.ts +0 -0
- package/types/middleware/rbacMiddleware.d.ts.map +0 -0
- package/types/models/RoleModel.d.ts +0 -0
- package/types/models/RoleModel.d.ts.map +0 -0
- package/types/models/TenantModel.d.ts +0 -0
- package/types/models/TenantModel.d.ts.map +0 -0
- package/types/models/UserApiKeyModel.d.ts +0 -0
- package/types/models/UserApiKeyModel.d.ts.map +0 -0
- package/types/models/UserGroupModel.d.ts +0 -0
- package/types/models/UserGroupModel.d.ts.map +0 -0
- package/types/models/UserModel.d.ts +0 -0
- package/types/models/UserModel.d.ts.map +0 -0
- package/types/permissions/IdentityPermissions.d.ts +0 -0
- package/types/permissions/IdentityPermissions.d.ts.map +0 -0
- package/types/permissions/RolePermissions.d.ts +0 -0
- package/types/permissions/RolePermissions.d.ts.map +0 -0
- package/types/permissions/TenantPermissions.d.ts +0 -0
- package/types/permissions/TenantPermissions.d.ts.map +0 -0
- package/types/permissions/UserApiKeyPermissions.d.ts +0 -0
- package/types/permissions/UserApiKeyPermissions.d.ts.map +0 -0
- package/types/permissions/UserPermissions.d.ts +0 -0
- package/types/permissions/UserPermissions.d.ts.map +0 -0
- package/types/permissions/index.d.ts +0 -0
- package/types/permissions/index.d.ts.map +0 -0
- package/types/rbac/Rbac.d.ts +0 -0
- package/types/rbac/Rbac.d.ts.map +0 -0
- package/types/repository/mongo/RoleMongoRepository.d.ts +0 -0
- package/types/repository/mongo/RoleMongoRepository.d.ts.map +0 -0
- package/types/repository/mongo/TenantMongoRepository.d.ts +0 -0
- package/types/repository/mongo/TenantMongoRepository.d.ts.map +0 -0
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts +0 -0
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts.map +0 -0
- package/types/repository/mongo/UserMongoRepository.d.ts +0 -0
- package/types/repository/mongo/UserMongoRepository.d.ts.map +0 -0
- package/types/repository/sqlite/RoleSqliteRepository.d.ts +0 -0
- package/types/repository/sqlite/RoleSqliteRepository.d.ts.map +0 -0
- package/types/repository/sqlite/TenantSqliteRepository.d.ts +0 -0
- package/types/repository/sqlite/TenantSqliteRepository.d.ts.map +0 -0
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts +0 -0
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts.map +0 -0
- package/types/repository/sqlite/UserSqliteRepository.d.ts +0 -0
- package/types/repository/sqlite/UserSqliteRepository.d.ts.map +0 -0
- package/types/routes/RoleRoutes.d.ts +0 -0
- package/types/routes/RoleRoutes.d.ts.map +0 -0
- package/types/routes/TenantRoutes.d.ts +0 -0
- package/types/routes/TenantRoutes.d.ts.map +0 -0
- package/types/routes/UserApiKeyRoutes.d.ts +0 -0
- package/types/routes/UserApiKeyRoutes.d.ts.map +0 -0
- package/types/routes/UserAvatarRoutes.d.ts +4 -0
- package/types/routes/UserAvatarRoutes.d.ts.map +1 -0
- package/types/routes/UserRoutes.d.ts +0 -0
- package/types/routes/UserRoutes.d.ts.map +0 -0
- package/types/schemas/RegisterSchema.d.ts +4 -4
- package/types/schemas/RoleSchema.d.ts +6 -6
- package/types/schemas/TenantSchema.d.ts +4 -4
- package/types/schemas/UserApiKeySchema.d.ts +4 -4
- package/types/schemas/UserSchema.d.ts +21 -21
- package/types/services/PermissionService.d.ts +0 -0
- package/types/services/PermissionService.d.ts.map +0 -0
- package/types/services/RoleService.d.ts +0 -0
- package/types/services/RoleService.d.ts.map +0 -0
- package/types/services/TenantService.d.ts +0 -0
- package/types/services/TenantService.d.ts.map +0 -0
- package/types/services/UserApiKeyService.d.ts +0 -0
- package/types/services/UserApiKeyService.d.ts.map +0 -0
- package/types/services/UserService.d.ts +0 -0
- package/types/services/UserService.d.ts.map +0 -0
- package/types/setup/CreateOrUpdateRole.d.ts +0 -0
- package/types/setup/CreateOrUpdateRole.d.ts.map +0 -0
- package/types/setup/CreateUserIfNotExist.d.ts +0 -0
- package/types/setup/CreateUserIfNotExist.d.ts.map +0 -0
- package/types/setup/LoadIdentityConfigFromEnv.d.ts +0 -0
- package/types/setup/LoadIdentityConfigFromEnv.d.ts.map +0 -0
- package/types/setup/LoadPermissions.d.ts +0 -0
- package/types/setup/LoadPermissions.d.ts.map +0 -0
- package/types/setup/RecoveryUserPassword.d.ts +0 -0
- package/types/setup/RecoveryUserPassword.d.ts.map +0 -0
- package/types/utils/AuthUtils.d.ts +0 -0
- package/types/utils/AuthUtils.d.ts.map +0 -0
- package/types/zod/EndpointZod.d.ts +20 -0
- package/types/zod/EndpointZod.d.ts.map +1 -0
- package/types/zod/RoleZod.d.ts +10 -0
- package/types/zod/RoleZod.d.ts.map +1 -0
- package/types/zod/TenantSchema.d.ts +26 -0
- package/types/zod/TenantSchema.d.ts.map +1 -0
- package/types/zod/TenantZod.d.ts +20 -0
- package/types/zod/TenantZod.d.ts.map +1 -0
- package/types/zod/UserApiKeyZod.d.ts +36 -0
- package/types/zod/UserApiKeyZod.d.ts.map +1 -0
- package/types/zod/UserZod.d.ts +53 -0
- package/types/zod/UserZod.d.ts.map +1 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -301,7 +301,7 @@ class UserController extends AbstractFastifyController {
|
|
|
301
301
|
}
|
|
302
302
|
async changePassword(request, reply) {
|
|
303
303
|
try {
|
|
304
|
-
request.rbac.assertPermission(UserPermissions.
|
|
304
|
+
request.rbac.assertPermission(UserPermissions.ChangePassword);
|
|
305
305
|
const userId = request.params.id;
|
|
306
306
|
if (!userId) {
|
|
307
307
|
throw new UnauthorizedError();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import UserRegistryService from "../services/UserRegistryService.js";
|
|
2
|
+
import { COMMON, CommonConfig, DraxConfig } from "@drax/common-back";
|
|
3
|
+
import UserRegistrySqliteRepository from "../repository/sqlite/UserRegistrySqliteRepository.js";
|
|
4
|
+
import UserRegistryMongoRepository from "../repository/mongo/UserRegistryMongoRepository.js";
|
|
5
|
+
let userRegistryService;
|
|
6
|
+
const UserRegistryServiceFactory = (verbose = false) => {
|
|
7
|
+
if (!userRegistryService) {
|
|
8
|
+
let repository;
|
|
9
|
+
switch (DraxConfig.getOrLoad(CommonConfig.DbEngine)) {
|
|
10
|
+
case COMMON.DB_ENGINES.MONGODB:
|
|
11
|
+
repository = new UserRegistryMongoRepository();
|
|
12
|
+
break;
|
|
13
|
+
case COMMON.DB_ENGINES.SQLITE:
|
|
14
|
+
const dbFile = DraxConfig.getOrLoad(CommonConfig.SqliteDbFile);
|
|
15
|
+
repository = new UserRegistrySqliteRepository(dbFile, verbose);
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
throw new Error("DraxConfig.DB_ENGINE must be one of " + Object.values(COMMON.DB_ENGINES).join(", "));
|
|
19
|
+
}
|
|
20
|
+
userRegistryService = new UserRegistryService(repository);
|
|
21
|
+
}
|
|
22
|
+
return userRegistryService;
|
|
23
|
+
};
|
|
24
|
+
export default UserRegistryServiceFactory;
|
|
File without changes
|
package/dist/graphql/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/models/RoleModel.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/models/UserModel.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/rbac/Rbac.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { StoreManager, UploadFileError, DraxConfig, CommonConfig, UnauthorizedError } from "@drax/common-back";
|
|
3
|
+
import UserServiceFactory from "../factory/UserServiceFactory.js";
|
|
4
|
+
import IdentityConfig from "../config/IdentityConfig.js";
|
|
5
|
+
const BASE_FILE_DIR = DraxConfig.getOrLoad(CommonConfig.FileDir) || 'files';
|
|
6
|
+
const AVATAR_DIR = DraxConfig.getOrLoad(IdentityConfig.AvatarDir) || 'avatar';
|
|
7
|
+
const BASE_URL = DraxConfig.getOrLoad(CommonConfig.BaseUrl) ? DraxConfig.get(CommonConfig.BaseUrl).replace(/\/$/, '') : '';
|
|
8
|
+
async function UserAvatarRoutes(fastify, options) {
|
|
9
|
+
fastify.post('/api/user/avatar', async (request, reply) => {
|
|
10
|
+
try {
|
|
11
|
+
request.rbac.assertAuthenticated();
|
|
12
|
+
const userId = request.rbac.getAuthUser.id;
|
|
13
|
+
const data = await request.file();
|
|
14
|
+
const file = {
|
|
15
|
+
filename: data.filename,
|
|
16
|
+
fileStream: data.file,
|
|
17
|
+
mimetype: data.mimetype
|
|
18
|
+
};
|
|
19
|
+
const destinationPath = join(BASE_FILE_DIR, AVATAR_DIR);
|
|
20
|
+
const storedFile = await StoreManager.saveFile(file, destinationPath);
|
|
21
|
+
const urlFile = BASE_URL + '/api/user/avatar/' + storedFile.filename;
|
|
22
|
+
//Save into DB
|
|
23
|
+
const userService = UserServiceFactory();
|
|
24
|
+
await userService.changeAvatar(userId, urlFile);
|
|
25
|
+
return {
|
|
26
|
+
filename: storedFile.filename,
|
|
27
|
+
size: storedFile.size,
|
|
28
|
+
mimetype: storedFile.mimetype,
|
|
29
|
+
url: urlFile,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
if (e instanceof UploadFileError) {
|
|
35
|
+
reply.statusCode = e.statusCode;
|
|
36
|
+
reply.send({ error: e.message });
|
|
37
|
+
}
|
|
38
|
+
else if (e instanceof UnauthorizedError) {
|
|
39
|
+
reply.statusCode = e.statusCode;
|
|
40
|
+
reply.send({ error: e.message });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
reply.statusCode = 500;
|
|
44
|
+
reply.send({ error: 'INTERNAL_SERVER_ERROR' });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
fastify.get('/api/user/avatar/:filename', async (request, reply) => {
|
|
49
|
+
try {
|
|
50
|
+
const filename = request.params.filename;
|
|
51
|
+
const subPath = 'avatar';
|
|
52
|
+
const fileDir = join(BASE_FILE_DIR, subPath);
|
|
53
|
+
console.log("FILE_DIR: ", fileDir, " FILENAME:", filename);
|
|
54
|
+
return reply.sendFile(filename, fileDir);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error(e);
|
|
58
|
+
if (e instanceof UnauthorizedError) {
|
|
59
|
+
reply.statusCode = e.statusCode;
|
|
60
|
+
reply.send({ error: e.message });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
reply.statusCode = 500;
|
|
64
|
+
reply.send({ error: 'INTERNAL_SERVER_ERROR' });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export default UserAvatarRoutes;
|
|
70
|
+
export { UserAvatarRoutes };
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ import { object, string, date, record, any } from "zod";
|
|
|
2
2
|
const TenantBaseSchema = object({
|
|
3
3
|
name: string({ required_error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required")
|
|
5
|
-
|
|
5
|
+
//.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
6
|
});
|
|
7
7
|
const TenantSchema = TenantBaseSchema.extend({
|
|
8
8
|
_id: string(),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/utils/AuthUtils.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { object, string } from "zod";
|
|
2
|
+
const roleSchema = object({
|
|
3
|
+
name: string({ required_error: "validation.required" })
|
|
4
|
+
.min(1, "validation.required")
|
|
5
|
+
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
|
+
});
|
|
7
|
+
export default roleSchema;
|
|
8
|
+
export { roleSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { object, string, date } from "zod";
|
|
2
|
+
const TenantBaseSchema = object({
|
|
3
|
+
name: string({ required_error: "validation.required" })
|
|
4
|
+
.min(1, "validation.required")
|
|
5
|
+
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
|
+
});
|
|
7
|
+
const TenantSchema = TenantBaseSchema.extend({
|
|
8
|
+
id: string(),
|
|
9
|
+
createdAt: date(),
|
|
10
|
+
updatedAt: date()
|
|
11
|
+
});
|
|
12
|
+
export { TenantSchema, TenantBaseSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { object, string } from "zod";
|
|
2
|
+
const TenantBaseSchema = object({
|
|
3
|
+
name: string({ required_error: "validation.required" })
|
|
4
|
+
.min(1, "validation.required")
|
|
5
|
+
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
|
+
});
|
|
7
|
+
const TenantSchema = TenantBaseSchema.extend({
|
|
8
|
+
id: string(),
|
|
9
|
+
});
|
|
10
|
+
export { TenantSchema, TenantBaseSchema };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { array, object, string } from "zod";
|
|
2
|
+
const userApiKeyBaseSchema = object({
|
|
3
|
+
name: string({ required_error: "validation.required" })
|
|
4
|
+
.min(1, "validation.required"),
|
|
5
|
+
ipv4: array(string().ip({ version: "v4", message: 'validation.invalidIpv4' })),
|
|
6
|
+
ipv6: array(string().ip({ version: "v6", message: 'validation.invalidIpv6' })),
|
|
7
|
+
});
|
|
8
|
+
const userApiKeySchema = userApiKeyBaseSchema.extend({
|
|
9
|
+
id: string(),
|
|
10
|
+
createdBy: string(),
|
|
11
|
+
});
|
|
12
|
+
export default userApiKeyBaseSchema;
|
|
13
|
+
export { userApiKeyBaseSchema, userApiKeySchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { object, string } from "zod";
|
|
2
|
+
export const userBaseSchema = object({
|
|
3
|
+
name: string({ required_error: "validation.required" })
|
|
4
|
+
.min(1, "validation.required"),
|
|
5
|
+
username: string({ required_error: "validation.required" })
|
|
6
|
+
.min(1, "validation.required"),
|
|
7
|
+
email: string({ required_error: "validation.required" })
|
|
8
|
+
.email("validation.email.invalid"),
|
|
9
|
+
role: string({ required_error: "validation.required" })
|
|
10
|
+
.min(1, "validation.required")
|
|
11
|
+
});
|
|
12
|
+
export const createUserSchema = userBaseSchema.extend({
|
|
13
|
+
password: string({ required_error: "validation.required" })
|
|
14
|
+
.min(1, "validation.required")
|
|
15
|
+
.min(8, "validation.password.min8")
|
|
16
|
+
.max(64, "validation.password.max64"),
|
|
17
|
+
});
|
|
18
|
+
export const editUserSchema = userBaseSchema.extend({});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.34.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.
|
|
32
|
-
"@drax/crud-back": "^0.
|
|
33
|
-
"@drax/crud-share": "^0.
|
|
34
|
-
"@drax/email-back": "^0.
|
|
35
|
-
"@drax/identity-share": "^0.
|
|
31
|
+
"@drax/common-back": "^0.34.0",
|
|
32
|
+
"@drax/crud-back": "^0.34.0",
|
|
33
|
+
"@drax/crud-share": "^0.34.0",
|
|
34
|
+
"@drax/email-back": "^0.34.0",
|
|
35
|
+
"@drax/identity-share": "^0.34.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": "
|
|
66
|
+
"gitHead": "3a121099fcdd0814fd232d90aeac0b2086e2e625"
|
|
67
67
|
}
|
|
@@ -346,7 +346,7 @@ class UserController extends AbstractFastifyController<IUser, IUserCreate, IUser
|
|
|
346
346
|
|
|
347
347
|
async changePassword(request, reply) {
|
|
348
348
|
try {
|
|
349
|
-
request.rbac.assertPermission(UserPermissions.
|
|
349
|
+
request.rbac.assertPermission(UserPermissions.ChangePassword)
|
|
350
350
|
const userId = request.params.id
|
|
351
351
|
if (!userId) {
|
|
352
352
|
throw new UnauthorizedError()
|
|
@@ -3,7 +3,7 @@ import { object, string, date, record, any } from "zod"
|
|
|
3
3
|
const TenantBaseSchema = object({
|
|
4
4
|
name: string({ required_error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required")
|
|
6
|
-
|
|
6
|
+
//.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
|
package/test.db
ADDED
|
Binary file
|