@drax/identity-back 0.1.0 → 0.1.4
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/routes/UserApiKeyRoutes.js +3 -3
- package/dist/services/RoleService.js +34 -8
- package/dist/services/TenantService.js +42 -11
- package/dist/services/UserApiKeyService.js +36 -11
- package/dist/services/UserService.js +34 -8
- package/package.json +2 -2
- package/src/routes/UserApiKeyRoutes.ts +3 -3
- package/src/services/RoleService.ts +41 -16
- package/src/services/TenantService.ts +49 -17
- package/src/services/UserApiKeyService.ts +42 -17
- package/src/services/UserService.ts +74 -48
- package/tsconfig.tsbuildinfo +1 -1
- package/types/config/IdentityConfig.d.ts +12 -0
- package/types/config/IdentityConfig.d.ts.map +1 -0
- package/types/errors/BadCredentialsError.d.ts +6 -0
- package/types/errors/BadCredentialsError.d.ts.map +1 -0
- package/types/errors/UnauthorizedError.d.ts +6 -0
- package/types/errors/UnauthorizedError.d.ts.map +1 -0
- package/types/factory/RoleServiceFactory.d.ts +4 -0
- package/types/factory/TenantServiceFactory.d.ts +4 -0
- package/types/factory/UserApiKeyServiceFactory.d.ts +4 -0
- package/types/factory/UserServiceFactory.d.ts +4 -0
- package/types/graphql/index.d.ts +6 -0
- package/types/graphql/resolvers/role.resolvers.d.ts +52 -0
- package/types/graphql/resolvers/tenant.resolvers.d.ts +49 -0
- package/types/graphql/resolvers/user-api-key.resolvers.d.ts +37 -0
- package/types/graphql/resolvers/user.resolvers.d.ts +67 -0
- package/types/index.d.ts +35 -0
- package/types/interfaces/IRoleRepository.d.ts +9 -0
- package/types/interfaces/ITenantRepository.d.ts +9 -0
- package/types/interfaces/IUserApiKeyRepository.d.ts +7 -0
- package/types/interfaces/IUserRepository.d.ts +10 -0
- package/types/middleware/apiKeyMiddleware.d.ts +4 -0
- package/types/middleware/jwtMiddleware.d.ts +4 -0
- package/types/middleware/rbacMiddleware.d.ts +4 -0
- package/types/models/RoleModel.d.ts +16 -0
- package/types/models/TenantModel.d.ts +16 -0
- package/types/models/UserApiKeyModel.d.ts +16 -0
- package/types/models/UserGroupModel.d.ts +16 -0
- package/types/models/UserModel.d.ts +16 -0
- package/types/permissions/IdentityPermissions.d.ts +27 -0
- package/types/permissions/IdentityPermissions.d.ts.map +1 -0
- package/types/repository/mongo/RoleMongoRepository.d.ts +14 -0
- package/types/repository/mongo/TenantMongoRepository.d.ts +14 -0
- package/types/repository/mongo/UserApiKeyMongoRepository.d.ts +14 -0
- package/types/repository/mongo/UserMongoRepository.d.ts +17 -0
- package/types/repository/sqlite/RoleSqliteRepository.d.ts +22 -0
- package/types/repository/sqlite/TenantSqliteRepository.d.ts +19 -0
- package/types/repository/sqlite/UserSqliteRepository.d.ts +25 -0
- package/types/routes/RoleRoutes.d.ts +4 -0
- package/types/routes/TenantRoutes.d.ts +4 -0
- package/types/routes/UserApiKeyRoutes.d.ts +4 -0
- package/types/routes/UserAvatarRoutes.d.ts +4 -0
- package/types/routes/UserRoutes.d.ts +4 -0
- package/types/services/PermissionService.d.ts +9 -0
- package/types/services/PermissionService.d.ts.map +1 -0
- package/types/services/RoleService.d.ts +16 -0
- package/types/services/RoleService.d.ts.map +1 -1
- package/types/services/TenantService.d.ts +16 -0
- package/types/services/TenantService.d.ts.map +1 -1
- package/types/services/UserApiKeyService.d.ts +15 -0
- package/types/services/UserApiKeyService.d.ts.map +1 -1
- package/types/services/UserService.d.ts +21 -0
- package/types/services/UserService.d.ts.map +1 -1
- package/types/setup/CreateOrUpdateRole.d.ts +5 -0
- package/types/setup/CreateUserIfNotExist.d.ts +5 -0
- package/types/setup/LoadIdentityConfigFromEnv.d.ts +4 -0
- package/types/setup/LoadPermissions.d.ts +4 -0
- package/types/setup/LoadPermissions.d.ts.map +1 -0
- package/types/setup/RecoveryUserPassword.d.ts +4 -0
- package/types/utils/AuthUtils.d.ts +18 -0
- package/types/zod/RoleZod.d.ts +10 -0
- package/types/zod/RoleZod.d.ts.map +1 -0
- package/types/zod/TenantZod.d.ts +10 -0
- package/types/zod/TenantZod.d.ts.map +1 -0
- package/types/zod/UserZod.d.ts +53 -0
- package/types/zod/UserZod.d.ts.map +1 -0
|
@@ -41,7 +41,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
41
41
|
});
|
|
42
42
|
fastify.post('/api/user-api-keys', async (request, reply) => {
|
|
43
43
|
try {
|
|
44
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
44
|
+
request.rbac.assertPermission(IdentityPermissions.CreateUserApiKey);
|
|
45
45
|
const payload = request.body;
|
|
46
46
|
payload.user = request.rbac.authUser.id;
|
|
47
47
|
const userApiKeyService = UserApiKeyServiceFactory();
|
|
@@ -65,7 +65,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
65
65
|
});
|
|
66
66
|
fastify.put('/api/user-api-keys/:id', async (request, reply) => {
|
|
67
67
|
try {
|
|
68
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
68
|
+
request.rbac.assertPermission(IdentityPermissions.UpdateUserApiKey);
|
|
69
69
|
const id = request.params.id;
|
|
70
70
|
const payload = request.body;
|
|
71
71
|
const userApiKeyService = UserApiKeyServiceFactory();
|
|
@@ -93,7 +93,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
93
93
|
});
|
|
94
94
|
fastify.delete('/api/user-api-keys/:id', async (request, reply) => {
|
|
95
95
|
try {
|
|
96
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
96
|
+
request.rbac.assertPermission(IdentityPermissions.DeleteUserApiKey);
|
|
97
97
|
const id = request.params.id;
|
|
98
98
|
const userApiKeyService = UserApiKeyServiceFactory();
|
|
99
99
|
let r = await userApiKeyService.delete(id);
|
|
@@ -14,6 +14,7 @@ class RoleService {
|
|
|
14
14
|
return role;
|
|
15
15
|
}
|
|
16
16
|
catch (e) {
|
|
17
|
+
console.error("Error creating role", e);
|
|
17
18
|
if (e instanceof ZodError) {
|
|
18
19
|
throw ZodErrorToValidationError(e, roleData);
|
|
19
20
|
}
|
|
@@ -28,6 +29,7 @@ class RoleService {
|
|
|
28
29
|
return role;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
32
|
+
console.error("Error updating role", e);
|
|
31
33
|
if (e instanceof ZodError) {
|
|
32
34
|
throw ZodErrorToValidationError(e, roleData);
|
|
33
35
|
}
|
|
@@ -35,24 +37,48 @@ class RoleService {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
async delete(id) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
try {
|
|
41
|
+
const deletedRole = await this._repository.delete(id);
|
|
42
|
+
return deletedRole;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.error("Error deleting role", e);
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
49
|
async findById(id) {
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
try {
|
|
51
|
+
const role = await this._repository.findById(id);
|
|
52
|
+
return role;
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error("Error finding role by id", e);
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
44
58
|
}
|
|
45
59
|
async findByName(name) {
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
try {
|
|
61
|
+
const role = await this._repository.findByName(name);
|
|
62
|
+
return role;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error("Error finding role by name", e);
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
48
68
|
}
|
|
49
69
|
async fetchAll() {
|
|
50
70
|
const roles = await this._repository.fetchAll();
|
|
51
71
|
return roles;
|
|
52
72
|
}
|
|
53
73
|
async paginate({ page = 1, limit = 5, orderBy = '', orderDesc = false, search = '', filters = [] }) {
|
|
54
|
-
|
|
55
|
-
|
|
74
|
+
try {
|
|
75
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, orderDesc, search, filters });
|
|
76
|
+
return pagination;
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.error("Error paginating roles", e);
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
56
82
|
}
|
|
57
83
|
}
|
|
58
84
|
export default RoleService;
|
|
@@ -14,6 +14,7 @@ class TenantService {
|
|
|
14
14
|
return tenant;
|
|
15
15
|
}
|
|
16
16
|
catch (e) {
|
|
17
|
+
console.error("Error creating tenant", e);
|
|
17
18
|
if (e instanceof ZodError) {
|
|
18
19
|
throw ZodErrorToValidationError(e, tenantData);
|
|
19
20
|
}
|
|
@@ -28,6 +29,7 @@ class TenantService {
|
|
|
28
29
|
return tenant;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
32
|
+
console.error("Error updating tenant", e);
|
|
31
33
|
if (e instanceof ZodError) {
|
|
32
34
|
throw ZodErrorToValidationError(e, tenantData);
|
|
33
35
|
}
|
|
@@ -35,25 +37,54 @@ class TenantService {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
async delete(id) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
try {
|
|
41
|
+
const deletedTenant = await this._repository.delete(id);
|
|
42
|
+
return deletedTenant;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.error("Error deleting tenant", e);
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
async findById(id) {
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
try {
|
|
51
|
+
const tenant = await this._repository.findById(id);
|
|
52
|
+
return tenant;
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error("Error finding tenant by id", e);
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
async findByName(name) {
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
try {
|
|
61
|
+
const tenant = await this._repository.findByName(name);
|
|
62
|
+
return tenant;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error("Error finding tenant by name", e);
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
49
68
|
}
|
|
50
69
|
async fetchAll() {
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
try {
|
|
71
|
+
const tenants = await this._repository.fetchAll();
|
|
72
|
+
return tenants;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error("Error fetching all tenants", e);
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
53
78
|
}
|
|
54
79
|
async paginate({ page = 1, limit = 5, orderBy = '', orderDesc = false, search = '', filters = [] }) {
|
|
55
|
-
|
|
56
|
-
|
|
80
|
+
try {
|
|
81
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, orderDesc, search, filters });
|
|
82
|
+
return pagination;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
console.error("Error paginating tenants", e);
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
57
88
|
}
|
|
58
89
|
}
|
|
59
90
|
export default TenantService;
|
|
@@ -21,6 +21,7 @@ class UserApiKeyService {
|
|
|
21
21
|
return userApiKey;
|
|
22
22
|
}
|
|
23
23
|
catch (e) {
|
|
24
|
+
console.error("Error creating userApiKey", e);
|
|
24
25
|
if (e instanceof ZodError) {
|
|
25
26
|
throw ZodErrorToValidationError(e, userApiKeyData);
|
|
26
27
|
}
|
|
@@ -36,6 +37,7 @@ class UserApiKeyService {
|
|
|
36
37
|
return userApiKey;
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
40
|
+
console.error("Error updating userApiKey", e);
|
|
39
41
|
if (e instanceof ZodError) {
|
|
40
42
|
throw ZodErrorToValidationError(e, userApiKeyData);
|
|
41
43
|
}
|
|
@@ -43,23 +45,46 @@ class UserApiKeyService {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
async delete(id) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
try {
|
|
49
|
+
const deletedUserApiKey = await this._repository.delete(id);
|
|
50
|
+
return deletedUserApiKey;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.error("Error deleting userApiKey", e);
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
async findById(id) {
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
try {
|
|
59
|
+
const userApiKey = await this._repository.findById(id);
|
|
60
|
+
return userApiKey;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error("Error finding userApiKey by id", e);
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
53
66
|
}
|
|
54
67
|
async findBySecret(secret) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
try {
|
|
69
|
+
const APIKEY_SECRET = DraxConfig.getOrLoad(IdentityConfig.ApiKeySecret);
|
|
70
|
+
const hashedSecret = AuthUtils.generateHMAC(APIKEY_SECRET, secret);
|
|
71
|
+
const userApiKey = await this._repository.findBySecret(hashedSecret);
|
|
72
|
+
return userApiKey;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error("Error finding userApiKey by secret", e);
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
59
78
|
}
|
|
60
79
|
async paginate({ page = 1, limit = 5, orderBy = '', orderDesc = false, search = '', filters = [] }) {
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
try {
|
|
81
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, orderDesc, search, filters });
|
|
82
|
+
return pagination;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
console.error("Error paginating userApiKeys", e);
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
63
88
|
}
|
|
64
89
|
}
|
|
65
90
|
export default UserApiKeyService;
|
|
@@ -74,6 +74,7 @@ class UserService {
|
|
|
74
74
|
return user;
|
|
75
75
|
}
|
|
76
76
|
catch (e) {
|
|
77
|
+
console.error("Error creating user", e);
|
|
77
78
|
if (e instanceof ZodError) {
|
|
78
79
|
throw ZodErrorToValidationError(e, userData);
|
|
79
80
|
}
|
|
@@ -91,6 +92,7 @@ class UserService {
|
|
|
91
92
|
return user;
|
|
92
93
|
}
|
|
93
94
|
catch (e) {
|
|
95
|
+
console.error("Error updating user", e);
|
|
94
96
|
if (e instanceof ZodError) {
|
|
95
97
|
throw ZodErrorToValidationError(e, userData);
|
|
96
98
|
}
|
|
@@ -98,20 +100,44 @@ class UserService {
|
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
async delete(id) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
try {
|
|
104
|
+
const deletedRole = await this._repository.delete(id);
|
|
105
|
+
return deletedRole;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
console.error("Error deleting user", e);
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
103
111
|
}
|
|
104
112
|
async findById(id) {
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
try {
|
|
114
|
+
const user = await this._repository.findById(id);
|
|
115
|
+
return user;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.error("Error finding user by id", e);
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
122
|
async findByUsername(username) {
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
try {
|
|
124
|
+
const user = await this._repository.findByUsername(username);
|
|
125
|
+
return user;
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
console.error("Error finding user by username", e);
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
111
131
|
}
|
|
112
132
|
async paginate({ page = 1, limit = 5, orderBy = '', orderDesc = false, search = '', filters = [] }) {
|
|
113
|
-
|
|
114
|
-
|
|
133
|
+
try {
|
|
134
|
+
const pagination = await this._repository.paginate({ page, limit, orderBy, orderDesc, search, filters });
|
|
135
|
+
return pagination;
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
console.error("Error paginating users", e);
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
115
141
|
}
|
|
116
142
|
}
|
|
117
143
|
export default UserService;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.4",
|
|
7
7
|
"description": "Identity module for user management, authentication and authorization.",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "types/index.d.ts",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"debug": "0"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "c9b0f92abc19463226d7faa8aa5c4f6631910740"
|
|
64
64
|
}
|
|
@@ -51,7 +51,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
51
51
|
|
|
52
52
|
fastify.post('/api/user-api-keys', async (request, reply): Promise<IUserApiKey> => {
|
|
53
53
|
try {
|
|
54
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
54
|
+
request.rbac.assertPermission(IdentityPermissions.CreateUserApiKey)
|
|
55
55
|
const payload = request.body
|
|
56
56
|
payload.user = request.rbac.authUser.id
|
|
57
57
|
|
|
@@ -76,7 +76,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
76
76
|
|
|
77
77
|
fastify.put('/api/user-api-keys/:id', async (request, reply): Promise<IUserApiKey> => {
|
|
78
78
|
try {
|
|
79
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
79
|
+
request.rbac.assertPermission(IdentityPermissions.UpdateUserApiKey)
|
|
80
80
|
const id = request.params.id
|
|
81
81
|
const payload = request.body
|
|
82
82
|
const userApiKeyService = UserApiKeyServiceFactory()
|
|
@@ -102,7 +102,7 @@ async function UserApiKeyRoutes(fastify, options) {
|
|
|
102
102
|
|
|
103
103
|
fastify.delete('/api/user-api-keys/:id', async (request, reply): Promise<any> => {
|
|
104
104
|
try {
|
|
105
|
-
request.rbac.assertPermission(IdentityPermissions.
|
|
105
|
+
request.rbac.assertPermission(IdentityPermissions.DeleteUserApiKey)
|
|
106
106
|
const id = request.params.id
|
|
107
107
|
const userApiKeyService = UserApiKeyServiceFactory()
|
|
108
108
|
let r = await userApiKeyService.delete(id)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {IRoleRepository} from "../interfaces/IRoleRepository";
|
|
2
|
-
import {
|
|
2
|
+
import {ValidationError, ZodErrorToValidationError} from "@drax/common-back"
|
|
3
3
|
import {roleSchema} from "../zod/RoleZod.js";
|
|
4
4
|
import {ZodError} from "zod";
|
|
5
5
|
import UnauthorizedError from "../errors/UnauthorizedError.js";
|
|
@@ -22,6 +22,7 @@ class RoleService {
|
|
|
22
22
|
const role = await this._repository.create(roleData)
|
|
23
23
|
return role
|
|
24
24
|
} catch (e) {
|
|
25
|
+
console.error("Error creating role", e)
|
|
25
26
|
if (e instanceof ZodError) {
|
|
26
27
|
throw ZodErrorToValidationError(e, roleData)
|
|
27
28
|
}
|
|
@@ -36,6 +37,7 @@ class RoleService {
|
|
|
36
37
|
const role = await this._repository.update(id, roleData)
|
|
37
38
|
return role
|
|
38
39
|
} catch (e) {
|
|
40
|
+
console.error("Error updating role", e)
|
|
39
41
|
if (e instanceof ZodError) {
|
|
40
42
|
throw ZodErrorToValidationError(e, roleData)
|
|
41
43
|
}
|
|
@@ -44,19 +46,35 @@ class RoleService {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
async delete(id: string): Promise<boolean> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
try {
|
|
50
|
+
const deletedRole = await this._repository.delete(id);
|
|
51
|
+
return deletedRole;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error("Error deleting role", e)
|
|
54
|
+
throw e
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
async findById(id: string): Promise<IRole | null> {
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
try{
|
|
60
|
+
const role: IRole = await this._repository.findById(id);
|
|
61
|
+
return role
|
|
62
|
+
}catch (e){
|
|
63
|
+
console.error("Error finding role by id", e)
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
async findByName(name: string): Promise<IRole | null> {
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
try{
|
|
71
|
+
const role: IRole = await this._repository.findByName(name);
|
|
72
|
+
return role
|
|
73
|
+
}catch (e){
|
|
74
|
+
console.error("Error finding role by name", e)
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
async fetchAll(): Promise<IRole[]> {
|
|
@@ -65,14 +83,21 @@ class RoleService {
|
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async paginate({
|
|
68
|
-
page= 1,
|
|
69
|
-
limit= 5,
|
|
70
|
-
orderBy= '',
|
|
71
|
-
orderDesc= false,
|
|
72
|
-
search= '',
|
|
73
|
-
filters= []
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
page = 1,
|
|
87
|
+
limit = 5,
|
|
88
|
+
orderBy = '',
|
|
89
|
+
orderDesc = false,
|
|
90
|
+
search = '',
|
|
91
|
+
filters = []
|
|
92
|
+
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IRole>> {
|
|
93
|
+
try{
|
|
94
|
+
const pagination = await this._repository.paginate({page, limit, orderBy, orderDesc, search, filters});
|
|
95
|
+
return pagination;
|
|
96
|
+
}catch (e){
|
|
97
|
+
console.error("Error paginating roles", e)
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
|
|
@@ -21,6 +21,7 @@ class TenantService {
|
|
|
21
21
|
const tenant = await this._repository.create(tenantData)
|
|
22
22
|
return tenant
|
|
23
23
|
} catch (e) {
|
|
24
|
+
console.error("Error creating tenant", e)
|
|
24
25
|
if (e instanceof ZodError) {
|
|
25
26
|
throw ZodErrorToValidationError(e, tenantData)
|
|
26
27
|
}
|
|
@@ -35,6 +36,7 @@ class TenantService {
|
|
|
35
36
|
const tenant = await this._repository.update(id, tenantData)
|
|
36
37
|
return tenant
|
|
37
38
|
} catch (e) {
|
|
39
|
+
console.error("Error updating tenant", e)
|
|
38
40
|
if (e instanceof ZodError) {
|
|
39
41
|
throw ZodErrorToValidationError(e, tenantData)
|
|
40
42
|
}
|
|
@@ -43,35 +45,65 @@ class TenantService {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async delete(id: string): Promise<boolean> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
try {
|
|
49
|
+
const deletedTenant = await this._repository.delete(id);
|
|
50
|
+
return deletedTenant;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("Error deleting tenant", e)
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
async findById(id: string): Promise<ITenant | null> {
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
try {
|
|
60
|
+
const tenant: ITenant = await this._repository.findById(id);
|
|
61
|
+
return tenant
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error("Error finding tenant by id", e)
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
async findByName(name: string): Promise<ITenant | null> {
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
try {
|
|
71
|
+
const tenant: ITenant = await this._repository.findByName(name);
|
|
72
|
+
return tenant
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.error("Error finding tenant by name", e)
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
|
|
59
78
|
}
|
|
60
79
|
|
|
61
80
|
async fetchAll(): Promise<ITenant[]> {
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
try {
|
|
82
|
+
const tenants: ITenant[] = await this._repository.fetchAll();
|
|
83
|
+
return tenants
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error("Error fetching all tenants", e)
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
|
|
64
89
|
}
|
|
65
90
|
|
|
66
91
|
async paginate({
|
|
67
|
-
page= 1,
|
|
68
|
-
limit= 5,
|
|
69
|
-
orderBy= '',
|
|
70
|
-
orderDesc= false,
|
|
71
|
-
search= '',
|
|
72
|
-
filters= []
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
page = 1,
|
|
93
|
+
limit = 5,
|
|
94
|
+
orderBy = '',
|
|
95
|
+
orderDesc = false,
|
|
96
|
+
search = '',
|
|
97
|
+
filters = []
|
|
98
|
+
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<ITenant>> {
|
|
99
|
+
try {
|
|
100
|
+
const pagination = await this._repository.paginate({page, limit, orderBy, orderDesc, search, filters});
|
|
101
|
+
return pagination;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error("Error paginating tenants", e)
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
|
|
75
107
|
}
|
|
76
108
|
|
|
77
109
|
|
|
@@ -28,6 +28,7 @@ class UserApiKeyService {
|
|
|
28
28
|
userApiKey.secret = secret
|
|
29
29
|
return userApiKey
|
|
30
30
|
} catch (e) {
|
|
31
|
+
console.error("Error creating userApiKey", e)
|
|
31
32
|
if (e instanceof ZodError) {
|
|
32
33
|
throw ZodErrorToValidationError(e, userApiKeyData)
|
|
33
34
|
}
|
|
@@ -43,6 +44,7 @@ class UserApiKeyService {
|
|
|
43
44
|
const userApiKey = await this._repository.update(id, userApiKeyData)
|
|
44
45
|
return userApiKey
|
|
45
46
|
} catch (e) {
|
|
47
|
+
console.error("Error updating userApiKey", e)
|
|
46
48
|
if (e instanceof ZodError) {
|
|
47
49
|
throw ZodErrorToValidationError(e, userApiKeyData)
|
|
48
50
|
}
|
|
@@ -51,33 +53,56 @@ class UserApiKeyService {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
async delete(id: string): Promise<boolean> {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
try {
|
|
57
|
+
const deletedUserApiKey = await this._repository.delete(id);
|
|
58
|
+
return deletedUserApiKey;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error("Error deleting userApiKey", e)
|
|
61
|
+
throw e
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
async findById(id: string): Promise<IUserApiKey | null> {
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
try{
|
|
68
|
+
const userApiKey: IUserApiKey = await this._repository.findById(id);
|
|
69
|
+
return userApiKey
|
|
70
|
+
}catch (e){
|
|
71
|
+
console.error("Error finding userApiKey by id", e)
|
|
72
|
+
throw e
|
|
73
|
+
}
|
|
74
|
+
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
async findBySecret(secret: string): Promise<IUserApiKey | null> {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
try{
|
|
79
|
+
const APIKEY_SECRET = DraxConfig.getOrLoad(IdentityConfig.ApiKeySecret)
|
|
80
|
+
const hashedSecret = AuthUtils.generateHMAC(APIKEY_SECRET, secret)
|
|
81
|
+
const userApiKey: IUserApiKey = await this._repository.findBySecret(hashedSecret);
|
|
82
|
+
return userApiKey
|
|
83
|
+
}catch (e){
|
|
84
|
+
console.error("Error finding userApiKey by secret", e)
|
|
85
|
+
throw e
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
|
|
72
91
|
async paginate({
|
|
73
|
-
page= 1,
|
|
74
|
-
limit= 5,
|
|
75
|
-
orderBy= '',
|
|
76
|
-
orderDesc= false,
|
|
77
|
-
search= '',
|
|
78
|
-
filters= []
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
page = 1,
|
|
93
|
+
limit = 5,
|
|
94
|
+
orderBy = '',
|
|
95
|
+
orderDesc = false,
|
|
96
|
+
search = '',
|
|
97
|
+
filters = []
|
|
98
|
+
}: IDraxPaginateOptions): Promise<IDraxPaginateResult<IUserApiKey>> {
|
|
99
|
+
try {
|
|
100
|
+
const pagination = await this._repository.paginate({page, limit, orderBy, orderDesc, search, filters});
|
|
101
|
+
return pagination;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.error("Error paginating userApiKeys", e)
|
|
104
|
+
throw e
|
|
105
|
+
}
|
|
81
106
|
}
|
|
82
107
|
|
|
83
108
|
|