@drax/identity-back 0.11.5 → 0.12.2
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/controllers/RoleController.js +8 -39
- package/dist/controllers/TenantController.js +1 -28
- package/dist/controllers/UserApiKeyController.js +3 -3
- package/dist/controllers/UserController.js +48 -209
- package/dist/errors/BadCredentialsError.js +12 -0
- package/dist/factory/RoleServiceFactory.js +1 -0
- package/dist/factory/TenantServiceFactory.js +1 -0
- package/dist/factory/UserApiKeyServiceFactory.js +5 -4
- package/dist/factory/UserServiceFactory.js +1 -0
- package/dist/graphql/resolvers/role.resolvers.js +2 -2
- package/dist/graphql/resolvers/tenant.resolvers.js +2 -2
- package/dist/graphql/resolvers/user-api-key.resolvers.js +2 -2
- package/dist/graphql/resolvers/user.resolvers.js +1 -1
- package/dist/index.js +6 -0
- package/dist/middleware/apiKeyMiddleware.js +2 -2
- package/dist/models/RoleModel.js +10 -7
- package/dist/models/TenantModel.js +11 -8
- package/dist/models/UserApiKeyModel.js +10 -7
- package/dist/models/UserGroupModel.js +7 -7
- package/dist/models/UserModel.js +10 -8
- package/dist/rbac/Rbac.js +10 -8
- package/dist/repository/mongo/RoleMongoRepository.js +20 -65
- package/dist/repository/mongo/TenantMongoRepository.js +18 -66
- package/dist/repository/mongo/UserApiKeyMongoRepository.js +29 -47
- package/dist/repository/mongo/UserMongoRepository.js +56 -85
- package/dist/repository/sqlite/RoleSqliteRepository.js +30 -115
- package/dist/repository/sqlite/TenantSqliteRepository.js +15 -105
- package/dist/repository/sqlite/UserApiKeySqliteRepository.js +42 -117
- package/dist/repository/sqlite/UserSqliteRepository.js +49 -130
- package/dist/routes/RoleRoutes.js +35 -10
- package/dist/routes/TenantRoutes.js +18 -9
- package/dist/routes/UserApiKeyRoutes.js +20 -4
- package/dist/routes/UserRoutes.js +92 -17
- package/dist/schemas/LoginSchema.js +9 -0
- package/dist/schemas/PasswordSchema.js +12 -0
- package/dist/schemas/RegisterSchema.js +19 -0
- package/dist/schemas/RoleSchema.js +23 -0
- package/dist/schemas/TenantSchema.js +13 -0
- package/dist/schemas/UserApiKeySchema.js +14 -0
- package/dist/schemas/UserSchema.js +39 -0
- package/dist/services/PermissionService.js +5 -5
- package/dist/services/RoleService.js +6 -6
- package/dist/services/TenantService.js +6 -6
- package/dist/services/UserApiKeyService.js +5 -5
- package/dist/services/UserService.js +14 -14
- package/dist/setup/CreateOrUpdateRole.js +5 -2
- package/dist/setup/CreateUserIfNotExist.js +3 -1
- package/dist/setup/RecoveryUserPassword.js +1 -1
- package/dist/zod/EndpointZod.js +9 -0
- package/dist/zod/TenantSchema.js +12 -0
- package/dist/zod/TenantZod.js +5 -3
- package/dist/zod/UserApiKeyZod.js +7 -3
- package/package.json +10 -9
- package/src/controllers/RoleController.ts +8 -36
- package/src/controllers/TenantController.ts +2 -25
- package/src/controllers/UserApiKeyController.ts +3 -3
- package/src/controllers/UserController.ts +50 -183
- package/src/errors/BadCredentialsError.ts +18 -1
- package/src/factory/RoleServiceFactory.ts +1 -0
- package/src/factory/TenantServiceFactory.ts +1 -0
- package/src/factory/UserApiKeyServiceFactory.ts +5 -4
- package/src/factory/UserServiceFactory.ts +1 -0
- package/src/graphql/resolvers/role.resolvers.ts +3 -2
- package/src/graphql/resolvers/tenant.resolvers.ts +3 -2
- package/src/graphql/resolvers/user-api-key.resolvers.ts +3 -2
- package/src/graphql/resolvers/user.resolvers.ts +2 -1
- package/src/index.ts +16 -0
- package/src/interfaces/ITenantRepository.ts +2 -2
- package/src/interfaces/IUserApiKeyRepository.ts +2 -2
- package/src/interfaces/IUserRepository.ts +3 -2
- package/src/middleware/apiKeyMiddleware.ts +2 -2
- package/src/models/RoleModel.ts +12 -7
- package/src/models/TenantModel.ts +13 -8
- package/src/models/UserApiKeyModel.ts +12 -7
- package/src/models/UserGroupModel.ts +7 -7
- package/src/models/UserModel.ts +10 -8
- package/src/rbac/Rbac.ts +12 -9
- package/src/repository/mongo/RoleMongoRepository.ts +23 -94
- package/src/repository/mongo/TenantMongoRepository.ts +19 -98
- package/src/repository/mongo/UserApiKeyMongoRepository.ts +31 -56
- package/src/repository/mongo/UserMongoRepository.ts +71 -130
- package/src/repository/sqlite/RoleSqliteRepository.ts +37 -146
- package/src/repository/sqlite/TenantSqliteRepository.ts +16 -156
- package/src/repository/sqlite/UserApiKeySqliteRepository.ts +46 -151
- package/src/repository/sqlite/UserSqliteRepository.ts +59 -173
- package/src/routes/RoleRoutes.ts +35 -12
- package/src/routes/TenantRoutes.ts +25 -9
- package/src/routes/UserApiKeyRoutes.ts +23 -7
- package/src/routes/UserRoutes.ts +117 -34
- package/src/schemas/LoginSchema.ts +12 -0
- package/src/schemas/PasswordSchema.ts +16 -0
- package/src/{zod/UserZod.ts → schemas/RegisterSchema.ts} +7 -10
- package/src/schemas/RoleSchema.ts +29 -0
- package/src/schemas/TenantSchema.ts +22 -0
- package/src/{zod/UserApiKeyZod.ts → schemas/UserApiKeySchema.ts} +8 -3
- package/src/schemas/UserSchema.ts +57 -0
- package/src/services/PermissionService.ts +6 -5
- package/src/services/RoleService.ts +6 -6
- package/src/services/TenantService.ts +10 -10
- package/src/services/UserApiKeyService.ts +5 -5
- package/src/services/UserService.ts +15 -16
- package/src/setup/CreateOrUpdateRole.ts +7 -4
- package/src/setup/CreateUserIfNotExist.ts +5 -3
- package/src/setup/RecoveryUserPassword.ts +1 -1
- package/test/data-obj/apikey/root-mongo-user-apikey.ts +2 -1
- package/test/data-obj/roles/admin-sqlite-role.ts +2 -2
- package/test/data-obj/roles/operator-sqlite-role.ts +1 -1
- package/test/data-obj/tenants/company-sqlite-tenant.ts +6 -0
- package/test/data-obj/users/root-sqlite-user.ts +2 -2
- package/test/initializers/RoleSqliteInitializer.ts +1 -1
- package/test/repository/mongo/role-mongo-repository.test.ts +3 -3
- package/test/repository/mongo/user-apikey-mongo-repository.test.ts +5 -4
- package/test/repository/mongo/user-mongo-repository.test.ts +4 -4
- package/test/repository/sqlite/role-sqlite-repository.test.ts +21 -9
- package/test/repository/sqlite/tenant-sqlite-repository.test.ts +74 -0
- package/test/repository/sqlite/user-sqlite-repository.test.ts +15 -9
- package/test/routes/data/admin-role.ts +10 -0
- package/test/routes/data/root-user.ts +13 -0
- package/test/routes/helpers/CreateRootUserAndAdminRole.ts +17 -0
- package/test/routes/helpers/FastifyTestServerFactory.ts +34 -0
- package/test/routes/helpers/InitializePermissions.ts +23 -0
- package/test/routes/helpers/SetupIdentityDrax.ts +22 -0
- package/test/routes/tenant-route.test.ts +336 -0
- package/test/routes/user-route.test.ts +186 -0
- package/test/schemas/lab-schema.test.ts +110 -0
- package/test/service/mock-service.test.ts +3 -3
- package/test/service/role-service.test.ts +3 -3
- package/test/service/user-service.test.ts +16 -25
- package/test.db +0 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/controllers/RoleController.d.ts +0 -1
- package/types/controllers/RoleController.d.ts.map +1 -1
- package/types/controllers/TenantController.d.ts +0 -1
- package/types/controllers/TenantController.d.ts.map +1 -1
- package/types/controllers/UserController.d.ts +11 -4
- package/types/controllers/UserController.d.ts.map +1 -1
- package/types/errors/BadCredentialsError.d.ts +9 -1
- package/types/errors/BadCredentialsError.d.ts.map +1 -1
- package/types/factory/RoleServiceFactory.d.ts.map +1 -1
- package/types/factory/TenantServiceFactory.d.ts.map +1 -1
- package/types/factory/UserApiKeyServiceFactory.d.ts.map +1 -1
- package/types/factory/UserServiceFactory.d.ts.map +1 -1
- package/types/graphql/resolvers/role.resolvers.d.ts +3 -9
- package/types/graphql/resolvers/role.resolvers.d.ts.map +1 -1
- package/types/graphql/resolvers/tenant.resolvers.d.ts +3 -9
- package/types/graphql/resolvers/tenant.resolvers.d.ts.map +1 -1
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts +3 -9
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts.map +1 -1
- package/types/graphql/resolvers/user.resolvers.d.ts +3 -9
- package/types/graphql/resolvers/user.resolvers.d.ts.map +1 -1
- package/types/index.d.ts +5 -1
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/ITenantRepository.d.ts +2 -2
- package/types/interfaces/ITenantRepository.d.ts.map +1 -1
- package/types/interfaces/IUserApiKeyRepository.d.ts +2 -2
- package/types/interfaces/IUserApiKeyRepository.d.ts.map +1 -1
- package/types/interfaces/IUserRepository.d.ts +3 -2
- package/types/interfaces/IUserRepository.d.ts.map +1 -1
- package/types/models/RoleModel.d.ts +7 -7
- package/types/models/RoleModel.d.ts.map +1 -1
- package/types/models/TenantModel.d.ts +7 -7
- package/types/models/TenantModel.d.ts.map +1 -1
- package/types/models/UserApiKeyModel.d.ts +7 -7
- package/types/models/UserApiKeyModel.d.ts.map +1 -1
- package/types/models/UserGroupModel.d.ts +2 -2
- package/types/models/UserGroupModel.d.ts.map +1 -1
- package/types/models/UserModel.d.ts +7 -7
- package/types/models/UserModel.d.ts.map +1 -1
- package/types/rbac/Rbac.d.ts +1 -1
- package/types/rbac/Rbac.d.ts.map +1 -1
- package/types/repository/mongo/RoleMongoRepository.d.ts +9 -11
- package/types/repository/mongo/RoleMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/TenantMongoRepository.d.ts +8 -11
- package/types/repository/mongo/TenantMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts +12 -5
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts.map +1 -1
- package/types/repository/mongo/UserMongoRepository.d.ts +11 -12
- package/types/repository/mongo/UserMongoRepository.d.ts.map +1 -1
- package/types/repository/sqlite/RoleSqliteRepository.d.ts +14 -14
- package/types/repository/sqlite/RoleSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/TenantSqliteRepository.d.ts +12 -14
- package/types/repository/sqlite/TenantSqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts +15 -11
- package/types/repository/sqlite/UserApiKeySqliteRepository.d.ts.map +1 -1
- package/types/repository/sqlite/UserSqliteRepository.d.ts +15 -12
- package/types/repository/sqlite/UserSqliteRepository.d.ts.map +1 -1
- package/types/routes/RoleRoutes.d.ts.map +1 -1
- package/types/routes/TenantRoutes.d.ts.map +1 -1
- package/types/routes/UserApiKeyRoutes.d.ts.map +1 -1
- package/types/routes/UserRoutes.d.ts.map +1 -1
- package/types/schemas/LoginSchema.d.ts +20 -0
- package/types/schemas/LoginSchema.d.ts.map +1 -0
- package/types/schemas/PasswordSchema.d.ts +27 -0
- package/types/schemas/PasswordSchema.d.ts.map +1 -0
- package/types/schemas/RegisterSchema.d.ts +32 -0
- package/types/schemas/RegisterSchema.d.ts.map +1 -0
- package/types/schemas/RoleSchema.d.ts +67 -0
- package/types/schemas/RoleSchema.d.ts.map +1 -0
- package/types/schemas/TenantSchema.d.ts +29 -0
- package/types/schemas/TenantSchema.d.ts.map +1 -0
- package/types/schemas/UserApiKeySchema.d.ts +39 -0
- package/types/schemas/UserApiKeySchema.d.ts.map +1 -0
- package/types/schemas/UserSchema.d.ts +161 -0
- package/types/schemas/UserSchema.d.ts.map +1 -0
- package/types/services/PermissionService.d.ts +1 -0
- package/types/services/PermissionService.d.ts.map +1 -1
- package/types/services/TenantService.d.ts +3 -3
- package/types/services/TenantService.d.ts.map +1 -1
- package/types/services/UserService.d.ts.map +1 -1
- package/types/setup/CreateOrUpdateRole.d.ts +2 -2
- package/types/setup/CreateOrUpdateRole.d.ts.map +1 -1
- package/types/setup/CreateUserIfNotExist.d.ts +2 -2
- package/types/setup/CreateUserIfNotExist.d.ts.map +1 -1
- package/types/zod/EndpointZod.d.ts +20 -0
- package/types/zod/EndpointZod.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 +13 -3
- package/types/zod/TenantZod.d.ts.map +1 -1
- package/types/zod/UserApiKeyZod.d.ts +23 -3
- package/types/zod/UserApiKeyZod.d.ts.map +1 -1
- package/types/zod/UserZod.d.ts +6 -6
- package/src/zod/RoleZod.ts +0 -14
- package/src/zod/TenantZod.ts +0 -14
|
@@ -1,26 +1,42 @@
|
|
|
1
|
+
import {CrudSchemaBuilder} from "@drax/crud-back";
|
|
1
2
|
import TenantController from '../controllers/TenantController.js'
|
|
3
|
+
import {TenantSchema, TenantBaseSchema} from '../schemas/TenantSchema.js'
|
|
4
|
+
|
|
5
|
+
|
|
2
6
|
|
|
3
7
|
async function TenantRoutes(fastify, options) {
|
|
4
8
|
|
|
5
9
|
const controller: TenantController = new TenantController()
|
|
10
|
+
const schemas = new CrudSchemaBuilder(TenantSchema, TenantBaseSchema,TenantBaseSchema, 'tenant', 'openApi3', ['Identity']);
|
|
11
|
+
|
|
12
|
+
//Getters
|
|
13
|
+
fastify.get('/api/tenants/search', {schema: schemas.searchSchema}, (req, rep) => controller.search(req, rep))
|
|
14
|
+
|
|
15
|
+
fastify.get('/api/tenants/:id', {schema: schemas.findByIdSchema}, (req, rep) => controller.findById(req, rep))
|
|
16
|
+
|
|
17
|
+
fastify.get('/api/tenants/all', {schema: schemas.allSchema}, (req, rep) => controller.all(req, rep))
|
|
18
|
+
|
|
19
|
+
fastify.get('/api/tenants/find', {schema: schemas.findSchema}, (req, rep) => controller.find(req, rep))
|
|
20
|
+
|
|
21
|
+
fastify.get('/api/tenants/find-one', {schema: schemas.findOneSchema}, (req, rep) => controller.findOne(req, rep))
|
|
6
22
|
|
|
7
|
-
fastify.get('/api/tenants/
|
|
23
|
+
fastify.get('/api/tenants/find-by/:field/:value', {schema: schemas.findBySchema}, (req, rep) => controller.findBy(req, rep))
|
|
8
24
|
|
|
9
|
-
fastify.get('/api/tenants/
|
|
25
|
+
fastify.get('/api/tenants/find-one-by/:field/:value', {schema: schemas.findOneBySchema}, (req, rep) => controller.findOneBy(req, rep))
|
|
10
26
|
|
|
11
|
-
fastify.get('/api/tenants
|
|
27
|
+
fastify.get('/api/tenants', {schema: schemas.paginateSchema}, (req, rep) => controller.paginate(req, rep))
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
//Mutations
|
|
30
|
+
fastify.post('/api/tenants', {schema: schemas.createSchema}, (req, rep) => controller.create(req, rep))
|
|
14
31
|
|
|
15
|
-
fastify.
|
|
32
|
+
fastify.put('/api/tenants/:id', {schema: schemas.updateSchema}, (req, rep) => controller.update(req, rep))
|
|
16
33
|
|
|
17
|
-
fastify.
|
|
34
|
+
fastify.delete('/api/tenants/:id', {schema: schemas.deleteSchema}, (req, rep) => controller.delete(req, rep))
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
//Others
|
|
37
|
+
fastify.get('/api/tenants/export', {schema: schemas.exportSchema}, (req, rep) => controller.export(req, rep))
|
|
20
38
|
|
|
21
|
-
fastify.put('/api/tenants/:id', (req,rep) => controller.update(req,rep))
|
|
22
39
|
|
|
23
|
-
fastify.delete('/api/tenants/:id', (req,rep) => controller.delete(req,rep))
|
|
24
40
|
|
|
25
41
|
}
|
|
26
42
|
|
|
@@ -5,13 +5,29 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
5
5
|
|
|
6
6
|
const controller: UserApiKeyController = new UserApiKeyController()
|
|
7
7
|
|
|
8
|
-
fastify.get('/api/user-api-keys',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
fastify.
|
|
8
|
+
fastify.get('/api/user-api-keys', {
|
|
9
|
+
schema: {
|
|
10
|
+
tags: ['Identity'],
|
|
11
|
+
}
|
|
12
|
+
}, (req,rep) => controller.paginate(req,rep) )
|
|
13
|
+
|
|
14
|
+
fastify.post('/api/user-api-keys', {
|
|
15
|
+
schema: {
|
|
16
|
+
tags: ['Identity'],
|
|
17
|
+
}
|
|
18
|
+
}, (req,rep) => controller.create(req,rep))
|
|
19
|
+
|
|
20
|
+
fastify.put('/api/user-api-keys/:id', {
|
|
21
|
+
schema: {
|
|
22
|
+
tags: ['Identity'],
|
|
23
|
+
}
|
|
24
|
+
}, (req,rep) => controller.update(req,rep))
|
|
25
|
+
|
|
26
|
+
fastify.delete('/api/user-api-keys/:id', {
|
|
27
|
+
schema: {
|
|
28
|
+
tags: ['Identity'],
|
|
29
|
+
}
|
|
30
|
+
}, (req,rep) => controller.delete(req,rep))
|
|
15
31
|
|
|
16
32
|
|
|
17
33
|
}
|
package/src/routes/UserRoutes.ts
CHANGED
|
@@ -1,42 +1,125 @@
|
|
|
1
1
|
import UserController from "../controllers/UserController.js";
|
|
2
|
+
import {zodToJsonSchema} from "zod-to-json-schema";
|
|
3
|
+
import {CrudSchemaBuilder} from "@drax/crud-back";
|
|
4
|
+
import {LoginBodyRequestSchema, LoginBodyResponseSchema} from "../schemas/LoginSchema.js"
|
|
5
|
+
import {UserSchema, UserCreateSchema, UserUpdateSchema} from "../schemas/UserSchema.js";
|
|
6
|
+
import {RegisterBodyRequestSchema, RegisterBodyResponseSchema} from "../schemas/RegisterSchema.js";
|
|
7
|
+
import {
|
|
8
|
+
MyPasswordBodyRequestSchema,
|
|
9
|
+
PasswordBodyRequestSchema,
|
|
10
|
+
PasswordBodyResponseSchema
|
|
11
|
+
} from "../schemas/PasswordSchema.js";
|
|
2
12
|
|
|
3
13
|
async function UserRoutes(fastify, options) {
|
|
4
14
|
|
|
5
15
|
const controller: UserController = new UserController()
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fastify.get('/api/
|
|
10
|
-
|
|
11
|
-
fastify.get('/api/users/
|
|
12
|
-
|
|
13
|
-
fastify.get('/api/users
|
|
14
|
-
|
|
15
|
-
fastify.
|
|
16
|
-
|
|
17
|
-
fastify.
|
|
18
|
-
|
|
19
|
-
fastify.
|
|
20
|
-
|
|
21
|
-
fastify.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
const schemas = new CrudSchemaBuilder(UserSchema, UserCreateSchema, UserUpdateSchema, 'tenant', 'openApi3', ['Identity']);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
fastify.get('/api/users/search', {schema: schemas.searchSchema}, async (req, rep) => await controller.search(req, rep))
|
|
20
|
+
|
|
21
|
+
fastify.get('/api/users/export', {schema: schemas.exportSchema}, (req, rep) => controller.export(req, rep))
|
|
22
|
+
|
|
23
|
+
fastify.get('/api/users', {schema: schemas.paginateSchema}, (req, rep) => controller.paginate(req, rep))
|
|
24
|
+
|
|
25
|
+
fastify.post('/api/users', {schema: schemas.createSchema}, (req, rep) => controller.create(req, rep))
|
|
26
|
+
|
|
27
|
+
fastify.put('/api/users/:id', {schema: schemas.updateSchema}, (req, rep) => controller.update(req, rep))
|
|
28
|
+
|
|
29
|
+
fastify.delete('/api/users/:id', {schema: schemas.deleteSchema}, (req, rep) => controller.delete(req, rep))
|
|
30
|
+
|
|
31
|
+
fastify.post('/api/auth/login',
|
|
32
|
+
{
|
|
33
|
+
schema: {
|
|
34
|
+
tags: ['Auth'],
|
|
35
|
+
body: zodToJsonSchema(LoginBodyRequestSchema),
|
|
36
|
+
response: {
|
|
37
|
+
200: zodToJsonSchema(LoginBodyResponseSchema),
|
|
38
|
+
400: schemas.jsonErrorBodyResponse,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
(req, rep) => controller.auth(req, rep))
|
|
43
|
+
|
|
44
|
+
fastify.get('/api/auth/me', {
|
|
45
|
+
schema: {
|
|
46
|
+
tags: ['Auth'],
|
|
47
|
+
response: {
|
|
48
|
+
200: schemas.jsonEntitySchema,
|
|
49
|
+
401: schemas.jsonErrorBodyResponse,
|
|
50
|
+
500: schemas.jsonErrorBodyResponse,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}, (req, rep) => controller.me(req, rep))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
fastify.post('/api/users/register', {
|
|
57
|
+
schema: {
|
|
58
|
+
tags: ['Auth'],
|
|
59
|
+
body: zodToJsonSchema(RegisterBodyRequestSchema),
|
|
60
|
+
response: {
|
|
61
|
+
200: zodToJsonSchema(RegisterBodyResponseSchema),
|
|
62
|
+
400: schemas.jsonErrorBodyResponse,
|
|
63
|
+
500: schemas.jsonErrorBodyResponse,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}, (req, rep) => controller.register(req, rep))
|
|
67
|
+
|
|
68
|
+
fastify.get('/api/users/verify-email/:code', {
|
|
69
|
+
schema: {
|
|
70
|
+
tags: ['Auth'],
|
|
71
|
+
}
|
|
72
|
+
}, (req, rep) => controller.verifyEmail(req, rep))
|
|
73
|
+
|
|
74
|
+
fastify.get('/api/users/verify-phone/:code', {
|
|
75
|
+
schema: {
|
|
76
|
+
tags: ['Auth'],
|
|
77
|
+
}
|
|
78
|
+
}, (req, rep) => controller.verifyPhone(req, rep))
|
|
79
|
+
|
|
80
|
+
fastify.post('/api/users/password/change', {
|
|
81
|
+
schema: {
|
|
82
|
+
tags: ['Auth'],
|
|
83
|
+
body: zodToJsonSchema(MyPasswordBodyRequestSchema),
|
|
84
|
+
200: zodToJsonSchema(PasswordBodyResponseSchema),
|
|
85
|
+
400: schemas.jsonErrorBodyResponse,
|
|
86
|
+
500: schemas.jsonErrorBodyResponse,
|
|
87
|
+
}
|
|
88
|
+
}, (req, rep) => controller.changeMyPassword(req, rep))
|
|
89
|
+
|
|
90
|
+
fastify.post('/api/users/password/change/:id', {
|
|
91
|
+
schema: {
|
|
92
|
+
tags: ['Auth'],
|
|
93
|
+
body: zodToJsonSchema(PasswordBodyRequestSchema),
|
|
94
|
+
200: zodToJsonSchema(PasswordBodyResponseSchema),
|
|
95
|
+
400: schemas.jsonErrorBodyResponse,
|
|
96
|
+
500: schemas.jsonErrorBodyResponse,
|
|
97
|
+
}
|
|
98
|
+
}, (req, rep) => controller.changePassword(req, rep))
|
|
99
|
+
|
|
100
|
+
fastify.post('/api/users/password/recovery/request', {
|
|
101
|
+
schema: {
|
|
102
|
+
tags: ['Auth'],
|
|
103
|
+
}
|
|
104
|
+
}, (req, rep) => controller.passwordRecoveryRequest(req, rep))
|
|
105
|
+
|
|
106
|
+
fastify.post('/api/users/password/recovery/complete', {
|
|
107
|
+
schema: {
|
|
108
|
+
tags: ['Auth'],
|
|
109
|
+
}
|
|
110
|
+
}, (req, rep) => controller.recoveryPasswordComplete(req, rep))
|
|
111
|
+
|
|
112
|
+
fastify.post('/api/users/avatar', {
|
|
113
|
+
schema: {
|
|
114
|
+
tags: ['Auth'],
|
|
115
|
+
}
|
|
116
|
+
}, (req, rep) => controller.updateAvatar(req, rep))
|
|
117
|
+
|
|
118
|
+
fastify.get('/api/users/avatar/:filename', {
|
|
119
|
+
schema: {
|
|
120
|
+
tags: ['Auth'],
|
|
121
|
+
}
|
|
122
|
+
}, (req, rep) => controller.getAvatar(req, rep))
|
|
40
123
|
|
|
41
124
|
}
|
|
42
125
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
const LoginBodyRequestSchema = z.object({
|
|
4
|
+
username: z.string(),
|
|
5
|
+
password: z.string(),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const LoginBodyResponseSchema = z.object({
|
|
9
|
+
accessToken: z.string()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export {LoginBodyRequestSchema, LoginBodyResponseSchema}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
|
|
3
|
+
const MyPasswordBodyRequestSchema = z.object({
|
|
4
|
+
currentPassword: z.string(),
|
|
5
|
+
newPassword: z.string(),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const PasswordBodyRequestSchema = z.object({
|
|
9
|
+
newPassword: z.string()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const PasswordBodyResponseSchema = z.object({
|
|
13
|
+
message: z.string()
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export {MyPasswordBodyRequestSchema, PasswordBodyRequestSchema, PasswordBodyResponseSchema}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z, {string} from "zod"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const RegisterBodyRequestSchema = z.object({
|
|
4
4
|
name: string({ required_error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required"),
|
|
6
6
|
username: string({ required_error: "validation.required" })
|
|
7
7
|
.min(1, "validation.required"),
|
|
8
8
|
email: string({ required_error: "validation.required" })
|
|
9
9
|
.email("validation.email.invalid"),
|
|
10
|
-
|
|
11
|
-
.min(1, "validation.required")
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export const createUserSchema = userBaseSchema.extend({
|
|
10
|
+
phone: string({ required_error: "validation.required" }).optional(),
|
|
16
11
|
password: string({ required_error: "validation.required" })
|
|
17
12
|
.min(1, "validation.required")
|
|
18
13
|
.min(8, "validation.password.min8")
|
|
19
14
|
.max(64, "validation.password.max64"),
|
|
20
15
|
});
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const RegisterBodyResponseSchema = z.object({
|
|
18
|
+
success: z.boolean(),
|
|
19
|
+
message: z.string().optional(),
|
|
24
20
|
|
|
25
21
|
});
|
|
26
22
|
|
|
23
|
+
export {RegisterBodyRequestSchema, RegisterBodyResponseSchema}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {date, object, string, array, boolean} from "zod"
|
|
2
|
+
|
|
3
|
+
const RoleBaseSchema = object({
|
|
4
|
+
name: string({ required_error: "validation.required" })
|
|
5
|
+
.min(1, "validation.required")
|
|
6
|
+
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
7
|
+
permissions: array(string()).optional(),
|
|
8
|
+
childRoles: array(string()).optional(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const RoleSchema = RoleBaseSchema.extend({
|
|
12
|
+
_id: string(),
|
|
13
|
+
id: string().optional(),
|
|
14
|
+
permissions: array(string()).optional(),
|
|
15
|
+
readonly: boolean(),
|
|
16
|
+
childRoles: array(object({
|
|
17
|
+
_id: string(),
|
|
18
|
+
id: string().optional(),
|
|
19
|
+
name: string()
|
|
20
|
+
})).optional(),
|
|
21
|
+
createdAt: date().optional(),
|
|
22
|
+
updatedAt: date().optional()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export default RoleSchema
|
|
28
|
+
|
|
29
|
+
export {RoleSchema, RoleBaseSchema}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { object, string, date } from "zod"
|
|
2
|
+
|
|
3
|
+
const TenantBaseSchema = object({
|
|
4
|
+
name: string({ required_error: "validation.required" })
|
|
5
|
+
.min(1, "validation.required")
|
|
6
|
+
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const TenantSchema = TenantBaseSchema.extend({
|
|
11
|
+
_id: string(),
|
|
12
|
+
id: string().optional(),
|
|
13
|
+
createdAt: date(),
|
|
14
|
+
updatedAt: date()
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
TenantSchema,
|
|
21
|
+
TenantBaseSchema
|
|
22
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import {array, object, string} from "zod"
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const UserApiKeyBaseSchema = object({
|
|
4
4
|
name: string({ required_error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required"),
|
|
6
6
|
ipv4: array(string().ip({version: "v4", message: 'validation.invalidIpv4'})),
|
|
7
7
|
ipv6: array(string().ip({version: "v6", message: 'validation.invalidIpv6'})),
|
|
8
8
|
|
|
9
|
+
})
|
|
9
10
|
|
|
11
|
+
const UserApiKeySchema = UserApiKeyBaseSchema.extend({
|
|
12
|
+
_id: string(),
|
|
13
|
+
id: string().optional(),
|
|
14
|
+
createdBy: string(),
|
|
10
15
|
})
|
|
11
16
|
|
|
12
17
|
|
|
13
|
-
export default
|
|
18
|
+
export default UserApiKeyBaseSchema
|
|
14
19
|
|
|
15
|
-
export {
|
|
20
|
+
export {UserApiKeyBaseSchema, UserApiKeySchema}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {date, object, string, boolean, array} from "zod"
|
|
2
|
+
import {RoleSchema} from "./RoleSchema.js"
|
|
3
|
+
import {TenantSchema} from "./TenantSchema.js"
|
|
4
|
+
|
|
5
|
+
const UserBaseSchema = object({
|
|
6
|
+
name: string({ required_error: "validation.required" })
|
|
7
|
+
.min(1, "validation.required"),
|
|
8
|
+
username: string({ required_error: "validation.required" })
|
|
9
|
+
.min(1, "validation.required"),
|
|
10
|
+
email: string({ required_error: "validation.required" })
|
|
11
|
+
.email("validation.email.invalid"),
|
|
12
|
+
phone: string({ required_error: "validation.required" }).optional(),
|
|
13
|
+
active: boolean().optional(),
|
|
14
|
+
role: string({ required_error: "validation.required" })
|
|
15
|
+
.min(1, "validation.required"),
|
|
16
|
+
tenant: string({ required_error: "validation.required" }).nullable().optional()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const UserCreateSchema = UserBaseSchema.extend({
|
|
22
|
+
password: string({ required_error: "validation.required" })
|
|
23
|
+
.min(1, "validation.required")
|
|
24
|
+
.min(8, "validation.password.min8")
|
|
25
|
+
.max(64, "validation.password.max64"),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const UserUpdateSchema = UserBaseSchema.extend({
|
|
30
|
+
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const UserSchema = UserBaseSchema
|
|
34
|
+
.extend({
|
|
35
|
+
_id: string(),
|
|
36
|
+
role: object({
|
|
37
|
+
_id: string(),
|
|
38
|
+
id: string().optional(),
|
|
39
|
+
name: string(),
|
|
40
|
+
permissions: array(string())
|
|
41
|
+
}).optional(),
|
|
42
|
+
active: boolean(),
|
|
43
|
+
tenant: object({
|
|
44
|
+
_id: string(),
|
|
45
|
+
id: string().optional(),
|
|
46
|
+
name: string(),
|
|
47
|
+
}).nullable().optional(),
|
|
48
|
+
createdAt: date().optional()
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
UserBaseSchema,
|
|
54
|
+
UserSchema,
|
|
55
|
+
UserCreateSchema,
|
|
56
|
+
UserUpdateSchema,
|
|
57
|
+
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
const permissions: string[] = []
|
|
2
1
|
|
|
3
2
|
class PermissionService{
|
|
4
3
|
|
|
4
|
+
protected static permissions: string[] = []
|
|
5
|
+
|
|
5
6
|
static addPermission(permission: string){
|
|
6
7
|
if(PermissionService.hasPermission(permission)) return;
|
|
7
|
-
permissions.push(permission)
|
|
8
|
+
PermissionService.permissions.push(permission)
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
static removePermission(permission: string){
|
|
11
|
-
permissions.splice(permissions.indexOf(permission), 1)
|
|
12
|
+
PermissionService.permissions.splice(PermissionService.permissions.indexOf(permission), 1)
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
static hasPermission(permission: string): boolean{
|
|
15
|
-
return permissions.includes(permission)
|
|
16
|
+
return PermissionService.permissions.includes(permission)
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
static getPermissions(): string[]{
|
|
19
|
-
return permissions
|
|
20
|
+
return PermissionService.permissions
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {IRoleRepository} from "../interfaces/IRoleRepository";
|
|
2
2
|
import {UnauthorizedError, ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
3
3
|
import { AbstractService } from "@drax/crud-back"
|
|
4
|
-
import {
|
|
4
|
+
import {RoleBaseSchema} from "../schemas/RoleSchema.js";
|
|
5
5
|
import {ZodError} from "zod";
|
|
6
6
|
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
|
|
7
7
|
import type {IRoleBase, IRole} from "@drax/identity-share";
|
|
@@ -11,7 +11,7 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
|
|
|
11
11
|
_repository: IRoleRepository
|
|
12
12
|
|
|
13
13
|
constructor(roleRepostitory: IRoleRepository) {
|
|
14
|
-
super(roleRepostitory,
|
|
14
|
+
super(roleRepostitory, RoleBaseSchema)
|
|
15
15
|
this._repository = roleRepostitory
|
|
16
16
|
console.log("RoleService constructor")
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
|
|
|
19
19
|
async create(roleData: IRoleBase): Promise<IRole> {
|
|
20
20
|
try {
|
|
21
21
|
roleData.name = roleData?.name?.trim()
|
|
22
|
-
await
|
|
22
|
+
await RoleBaseSchema.parseAsync(roleData)
|
|
23
23
|
const role = await this._repository.create(roleData)
|
|
24
24
|
return role
|
|
25
25
|
} catch (e) {
|
|
@@ -34,7 +34,7 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
|
|
|
34
34
|
async update(id: string, roleData: IRoleBase): Promise<IRole> {
|
|
35
35
|
try {
|
|
36
36
|
roleData.name = roleData?.name?.trim()
|
|
37
|
-
await
|
|
37
|
+
await RoleBaseSchema.parseAsync(roleData)
|
|
38
38
|
const currentRole = await this.findById(id)
|
|
39
39
|
if(currentRole.readonly){
|
|
40
40
|
throw new ValidationError([{field:'name', reason:"role.readonly", value:roleData.name}])
|
|
@@ -53,7 +53,7 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
|
|
|
53
53
|
async systemUpdate(id: string, roleData: IRoleBase): Promise<IRole> {
|
|
54
54
|
try {
|
|
55
55
|
roleData.name = roleData?.name?.trim()
|
|
56
|
-
await
|
|
56
|
+
await RoleBaseSchema.parseAsync(roleData)
|
|
57
57
|
const role: IRole = await this._repository.update(id, roleData)
|
|
58
58
|
return role
|
|
59
59
|
} catch (e) {
|
|
@@ -125,7 +125,7 @@ class RoleService extends AbstractService<IRole, IRoleBase, IRoleBase> {
|
|
|
125
125
|
page = 1,
|
|
126
126
|
limit = 5,
|
|
127
127
|
orderBy = '',
|
|
128
|
-
order =
|
|
128
|
+
order = "asc",
|
|
129
129
|
search = '',
|
|
130
130
|
filters = []
|
|
131
131
|
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IRole>> {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
3
|
-
import {tenantSchema} from "../zod/TenantZod.js";
|
|
4
|
-
import {ZodError} from "zod";
|
|
5
|
-
import {ITenantBase, ITenant, IRole} from "@drax/identity-share";
|
|
6
|
-
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
|
|
1
|
+
import {ZodErrorToValidationError} from "@drax/common-back"
|
|
7
2
|
import {AbstractService} from "@drax/crud-back";
|
|
3
|
+
import {TenantBaseSchema} from "../schemas/TenantSchema.js";
|
|
4
|
+
import {ZodError} from "zod";
|
|
5
|
+
import type {ITenantBase, ITenant} from "@drax/identity-share";
|
|
6
|
+
import type {ITenantRepository} from "../interfaces/ITenantRepository";
|
|
7
|
+
import type {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
|
|
8
8
|
|
|
9
9
|
class TenantService extends AbstractService<ITenant,ITenantBase,ITenantBase> {
|
|
10
10
|
|
|
11
11
|
_repository: ITenantRepository
|
|
12
12
|
|
|
13
13
|
constructor(tenantRepostitory: ITenantRepository) {
|
|
14
|
-
super(tenantRepostitory,
|
|
14
|
+
super(tenantRepostitory, TenantBaseSchema)
|
|
15
15
|
this._repository = tenantRepostitory
|
|
16
16
|
console.log("TenantService constructor")
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ class TenantService extends AbstractService<ITenant,ITenantBase,ITenantBase> {
|
|
|
19
19
|
async create(tenantData: ITenantBase): Promise<ITenant> {
|
|
20
20
|
try {
|
|
21
21
|
tenantData.name = tenantData?.name?.trim()
|
|
22
|
-
await
|
|
22
|
+
await TenantBaseSchema.parseAsync(tenantData)
|
|
23
23
|
const tenant = await this._repository.create(tenantData)
|
|
24
24
|
return tenant
|
|
25
25
|
} catch (e) {
|
|
@@ -34,7 +34,7 @@ class TenantService extends AbstractService<ITenant,ITenantBase,ITenantBase> {
|
|
|
34
34
|
async update(id: string, tenantData: ITenantBase) {
|
|
35
35
|
try {
|
|
36
36
|
tenantData.name = tenantData?.name?.trim()
|
|
37
|
-
await
|
|
37
|
+
await TenantBaseSchema.parseAsync(tenantData)
|
|
38
38
|
const tenant = await this._repository.update(id, tenantData)
|
|
39
39
|
return tenant
|
|
40
40
|
} catch (e) {
|
|
@@ -99,7 +99,7 @@ class TenantService extends AbstractService<ITenant,ITenantBase,ITenantBase> {
|
|
|
99
99
|
page = 1,
|
|
100
100
|
limit = 5,
|
|
101
101
|
orderBy = '',
|
|
102
|
-
order =
|
|
102
|
+
order = "asc",
|
|
103
103
|
search = '',
|
|
104
104
|
filters = []
|
|
105
105
|
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<ITenant>> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {IUserApiKeyRepository} from "../interfaces/IUserApiKeyRepository";
|
|
2
2
|
import {DraxConfig, ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
3
|
-
import {
|
|
3
|
+
import {UserApiKeyBaseSchema} from "../schemas/UserApiKeySchema.js";
|
|
4
4
|
import {ZodError} from "zod";
|
|
5
5
|
import {IUserApiKeyBase, IUserApiKey} from "@drax/identity-share";
|
|
6
6
|
import {IDraxPaginateOptions, IDraxPaginateResult} from "@drax/crud-share";
|
|
@@ -14,7 +14,7 @@ class UserApiKeyService extends AbstractService<IUserApiKey, IUserApiKeyBase, IU
|
|
|
14
14
|
_repository: IUserApiKeyRepository
|
|
15
15
|
|
|
16
16
|
constructor(userApiKeyRepostitory: IUserApiKeyRepository) {
|
|
17
|
-
super(userApiKeyRepostitory,
|
|
17
|
+
super(userApiKeyRepostitory,UserApiKeyBaseSchema)
|
|
18
18
|
this._repository = userApiKeyRepostitory
|
|
19
19
|
console.log("UserApiKeyService constructor")
|
|
20
20
|
}
|
|
@@ -28,7 +28,7 @@ class UserApiKeyService extends AbstractService<IUserApiKey, IUserApiKeyBase, IU
|
|
|
28
28
|
throw new Error('ApiKey miss configuration')
|
|
29
29
|
}
|
|
30
30
|
userApiKeyData.secret = AuthUtils.generateHMAC(APIKEY_SECRET, secret)
|
|
31
|
-
await
|
|
31
|
+
await UserApiKeyBaseSchema.parseAsync(userApiKeyData)
|
|
32
32
|
const userApiKey = await this._repository.create(userApiKeyData)
|
|
33
33
|
userApiKey.secret = secret
|
|
34
34
|
return userApiKey
|
|
@@ -45,7 +45,7 @@ class UserApiKeyService extends AbstractService<IUserApiKey, IUserApiKeyBase, IU
|
|
|
45
45
|
try {
|
|
46
46
|
userApiKeyData.name = userApiKeyData?.name?.trim()
|
|
47
47
|
delete userApiKeyData.secret
|
|
48
|
-
await
|
|
48
|
+
await UserApiKeyBaseSchema.parseAsync(userApiKeyData)
|
|
49
49
|
const userApiKey = await this._repository.update(id, userApiKeyData)
|
|
50
50
|
return userApiKey
|
|
51
51
|
} catch (e) {
|
|
@@ -102,7 +102,7 @@ class UserApiKeyService extends AbstractService<IUserApiKey, IUserApiKeyBase, IU
|
|
|
102
102
|
page = 1,
|
|
103
103
|
limit = 5,
|
|
104
104
|
orderBy = '',
|
|
105
|
-
order =
|
|
105
|
+
order = "asc",
|
|
106
106
|
search = '',
|
|
107
107
|
filters = []
|
|
108
108
|
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IUserApiKey>> {
|