@getjones/test-infra 2.9.8 → 2.9.10
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/package.json +1 -1
- package/src/common/utils/configsUtil.js +22 -0
- package/src/common/utils/timeUtils.js +2 -0
- package/src/defaults/configs/polices.js +6 -2
- package/src/index.js +2 -1
- package/src/resources/virusFile.pdf +0 -0
- package/src/saas/internal-api/accounts/utils/utils.js +4 -12
- package/src/saas/internal-api/requirements/models/policy.model.js +1 -0
- package/src/saas/internal-api/users/api/users.api.js +6 -1
- package/src/saas/internal-api/users/api/users.service.js +34 -3
- package/src/saas/internal-api/users/models/users.model.js +11 -1
- package/src/saas/internal-api/users/utils/util.js +20 -1
- package/src/saas/openapi/users/user.model.js +10 -0
- package/src/saas/openapi/users/users.api.js +33 -0
- package/src/saas/openapi/users/users.service.js +41 -0
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const isUIConfig = (config, attributesConvertor) => {
|
|
2
|
+
const converterKeys = Object.keys(attributesConvertor);
|
|
3
|
+
const configKeys = Object.keys(config);
|
|
4
|
+
|
|
5
|
+
return converterKeys.some(key => configKeys.includes(key));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const objectConvertor = (config, attributesConvertor) => {
|
|
9
|
+
const covertConfig = {};
|
|
10
|
+
|
|
11
|
+
for (const field in config) {
|
|
12
|
+
const attributes = attributesConvertor[field];
|
|
13
|
+
covertConfig[attributes] = JSON.parse(config[field]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return covertConfig;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
isUIConfig,
|
|
21
|
+
objectConvertor
|
|
22
|
+
};
|
|
@@ -21,7 +21,8 @@ const policyNames = {
|
|
|
21
21
|
agreement: 'Agreement',
|
|
22
22
|
certificateHolder: 'Certificate Holder',
|
|
23
23
|
additionalInformation: 'Additional Information',
|
|
24
|
-
additionalInsured: 'Additional Insured'
|
|
24
|
+
additionalInsured: 'Additional Insured',
|
|
25
|
+
businessInterruptionIncomeInsurance: 'Business Interruption / Income Insurance'
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
const attributeNames = {
|
|
@@ -40,7 +41,10 @@ const attributeNames = {
|
|
|
40
41
|
coiAuthentication: 'COI authentication',
|
|
41
42
|
signature: 'Signature',
|
|
42
43
|
occur: 'Occur',
|
|
43
|
-
text: 'text'
|
|
44
|
+
text: 'text',
|
|
45
|
+
indemnityPeriod: 'Indemnity Period',
|
|
46
|
+
actualLossSustained: 'Actual Loss Sustained',
|
|
47
|
+
extraExpense: 'Extra Expense'
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
module.exports = {
|
package/src/index.js
CHANGED
|
@@ -78,7 +78,8 @@ const getOpenAPI = () => {
|
|
|
78
78
|
const requirements = require('./saas/openapi/requirements');
|
|
79
79
|
const requests = require('./saas/openapi/requests');
|
|
80
80
|
const coi = require('./saas/openapi/coi/coi.service');
|
|
81
|
-
const
|
|
81
|
+
const users = require('./saas/openapi/users/users.service');
|
|
82
|
+
const openAPI = { accounts, projects, tabs, requirements, requests, coi, users };
|
|
82
83
|
return openAPI;
|
|
83
84
|
};
|
|
84
85
|
|
|
Binary file
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const coreService = require('../api/core/accounts.core.service');
|
|
2
2
|
const CreateAccountModel = require('../models/core/create.account.model');
|
|
3
|
+
const configsUtil = require('../../../../common/utils/configsUtil');
|
|
3
4
|
|
|
4
5
|
const getOrCreateAccount = (context, accountName, email, { password, type } = {}) => {
|
|
5
6
|
const createAccountModel = new CreateAccountModel(
|
|
@@ -30,21 +31,12 @@ const deleteAccountByName = async (context, accountName) => {
|
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
const isUIConfig = config => {
|
|
33
|
-
|
|
34
|
-
const configKeys = Object.keys(config);
|
|
35
|
-
|
|
36
|
-
return convectorKeys.some(key => configKeys.includes(key));
|
|
34
|
+
return configsUtil.isUIConfig(config, attributesConvertor);
|
|
37
35
|
};
|
|
38
36
|
|
|
39
37
|
const parseAccountSettingsConfig = (accountId, settingsConfig) => {
|
|
40
|
-
const settings =
|
|
41
|
-
|
|
42
|
-
for (const field in settingsConfig) {
|
|
43
|
-
const attributes = attributesConvertor[field];
|
|
44
|
-
settings[attributes] = JSON.parse(settingsConfig[field]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return settings;
|
|
38
|
+
const settings = configsUtil.objectConvertor(settingsConfig, attributesConvertor);
|
|
39
|
+
return { ... settings, accountId };
|
|
48
40
|
};
|
|
49
41
|
|
|
50
42
|
module.exports = {
|
|
@@ -5,6 +5,7 @@ const Endpoints = {
|
|
|
5
5
|
invite: `${backendUrl}/saas/project/team-member`,
|
|
6
6
|
editUserProjects: `${backendUrl}/saas/project/team-member`,
|
|
7
7
|
editUserRole: userId => `${backendUrl}/secured/users/${userId}/change-role`,
|
|
8
|
+
editUserProfile: `${backendUrl}/saas/user/update`,
|
|
8
9
|
getByProjectId: projectId =>
|
|
9
10
|
`${backendUrl}/saas/project/${projectId}/team-members`,
|
|
10
11
|
getByEmail: email => `${backendUrl}/saas/team-member/by-email/${email}`,
|
|
@@ -84,6 +85,9 @@ const sendForgetPasswordMail = userEmail => {
|
|
|
84
85
|
const body = { email: userEmail };
|
|
85
86
|
return requests.postRequestHandler(Endpoints.sendForgetPasswordMail, body);
|
|
86
87
|
};
|
|
88
|
+
const editUserProfile = (editUserProfileModel, context) => {
|
|
89
|
+
return requests.postRequestHandler(Endpoints.editUserProfile, editUserProfileModel, context);
|
|
90
|
+
};
|
|
87
91
|
|
|
88
92
|
module.exports = {
|
|
89
93
|
invite,
|
|
@@ -100,5 +104,6 @@ module.exports = {
|
|
|
100
104
|
editUserEmailNotificationsSettings,
|
|
101
105
|
sendForgetPasswordMail,
|
|
102
106
|
createInnerSystemUser,
|
|
103
|
-
getInnerSystemUsersPerRole
|
|
107
|
+
getInnerSystemUsersPerRole,
|
|
108
|
+
editUserProfile
|
|
104
109
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { InviteUserModel, SignupUserModel, EditUserModel } = require('../models/users.model');
|
|
1
|
+
const { InviteUserModel, SignupUserModel, EditUserModel, EditUserProfileModel } = require('../models/users.model');
|
|
2
2
|
const { validateType } = require('../../../../common/validations/typeValidations');
|
|
3
|
-
const { getEnv } = require('../../../../env');
|
|
3
|
+
const { getEnv, getSystemUserIdentity } = require('../../../../env');
|
|
4
4
|
const { credentials } = getEnv();
|
|
5
5
|
const userAPI = require('./users.api');
|
|
6
6
|
const util = require('../utils/util');
|
|
@@ -147,6 +147,35 @@ const sendForgetPasswordMail = userEmail => {
|
|
|
147
147
|
return userAPI.sendForgetPasswordMail(userEmail);
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
const editUserProfile = async (email, fullName, userContext) => {
|
|
151
|
+
const systemUserContext = await getSystemUserIdentity(credentials.superUser).cookie;
|
|
152
|
+
const { data: user } = await getUserByEmail(email, systemUserContext);
|
|
153
|
+
|
|
154
|
+
const editUserProfileModel = new EditUserProfileModel(user.id, email, user.role, fullName);
|
|
155
|
+
|
|
156
|
+
const response = await userAPI.editUserProfile(editUserProfileModel, userContext);
|
|
157
|
+
|
|
158
|
+
if (response.status !== httpResponseStatusCodes.OK) {
|
|
159
|
+
throw Error(`Failed to edit user id: [${user.id}] profile\n${response}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return getUserByEmail(email, systemUserContext);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const editUserSettings = async (email, config, userContext) => {
|
|
166
|
+
const systemUserContext = await getSystemUserIdentity(credentials.superUser).cookie;
|
|
167
|
+
const { data: user } = await getUserByEmail(email, systemUserContext);
|
|
168
|
+
|
|
169
|
+
const settingModel = util.getSettingsModel(config);
|
|
170
|
+
const response = await userAPI.editUserEmailNotificationsSettings(user.id, settingModel, userContext);
|
|
171
|
+
|
|
172
|
+
if (response.status !== httpResponseStatusCodes.OK) {
|
|
173
|
+
throw Error(`Failed to edit user id: [${user.id}] settings\n${response}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return getUserByEmail(email, systemUserContext);
|
|
177
|
+
};
|
|
178
|
+
|
|
150
179
|
module.exports = {
|
|
151
180
|
inviteUser,
|
|
152
181
|
signupUser,
|
|
@@ -162,5 +191,7 @@ module.exports = {
|
|
|
162
191
|
reinviteUser,
|
|
163
192
|
editUserEmailNotificationsSettings,
|
|
164
193
|
sendForgetPasswordMail,
|
|
165
|
-
getOrCreateInnerSystemUser
|
|
194
|
+
getOrCreateInnerSystemUser,
|
|
195
|
+
editUserProfile,
|
|
196
|
+
editUserSettings
|
|
166
197
|
};
|
|
@@ -24,8 +24,18 @@ class EditUserModel {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
class EditUserProfileModel {
|
|
28
|
+
constructor(subUserId, email, role, fullName) {
|
|
29
|
+
this.subUserId = subUserId;
|
|
30
|
+
this.email = email;
|
|
31
|
+
this.role = role;
|
|
32
|
+
this.fullName = fullName;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
module.exports = {
|
|
28
37
|
InviteUserModel,
|
|
29
38
|
SignupUserModel,
|
|
30
|
-
EditUserModel
|
|
39
|
+
EditUserModel,
|
|
40
|
+
EditUserProfileModel
|
|
31
41
|
};
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
const { SignupUserModel } = require('../models/users.model');
|
|
2
|
+
const { NotificationSettingsModel } = require('../models/notification.settings.model');
|
|
2
3
|
const usersApi = require('../api/users.api');
|
|
3
4
|
const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
|
|
5
|
+
const objectUtils = require('../../../../common/utils/configsUtil');
|
|
6
|
+
|
|
7
|
+
const attributesConvertor = {
|
|
8
|
+
'COI is not compliant.': 'auditNotCompliant',
|
|
9
|
+
'Policy is about to expire.': 'aboutToExpire',
|
|
10
|
+
'COI is compliant.': 'auditCompliant',
|
|
11
|
+
'Unresponsive contact.': 'missingCoi'
|
|
12
|
+
};
|
|
4
13
|
|
|
5
14
|
const getUserEncryptedData = async (email, role, context) => {
|
|
6
15
|
const response = await usersApi.getUserEncryptedData(email, role, context);
|
|
@@ -17,4 +26,14 @@ const getSignupUserModel = async (email, role, fullName, password, context) => {
|
|
|
17
26
|
return new SignupUserModel(fullName, role, password, userEncryptedData);
|
|
18
27
|
};
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
const getSettingsModel = settings => {
|
|
30
|
+
const isUIConfig = objectUtils.isUIConfig(settings, attributesConvertor);
|
|
31
|
+
|
|
32
|
+
const settingConfig = isUIConfig ?
|
|
33
|
+
objectUtils.objectConvertor(settings, attributesConvertor) :
|
|
34
|
+
settings;
|
|
35
|
+
|
|
36
|
+
return new NotificationSettingsModel(settingConfig);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
module.exports = { getSignupUserModel, getSettingsModel };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const requests = require('../../../common/requests/apiKeyAuth/requests');
|
|
2
|
+
const { openapiUrl } = require('../../../env').getEnv();
|
|
3
|
+
|
|
4
|
+
const Endpoints = {
|
|
5
|
+
createUser: `${openapiUrl}/users`,
|
|
6
|
+
updateUser: userId => `${openapiUrl}/users/${userId}`,
|
|
7
|
+
deleteUser: userId => `${openapiUrl}/users/${userId}`,
|
|
8
|
+
getUser: `${openapiUrl}/users`,
|
|
9
|
+
getAllUsers: `${openapiUrl}/users/all`
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const createUser = async (apiKey, user) => {
|
|
14
|
+
return requests.postRequestHandler(Endpoints.createUser, apiKey, user).then(res => res);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const updateUser = async (apiKey, user, userId) => {
|
|
18
|
+
return requests.patchRequestHandler(Endpoints.updateUser(userId), apiKey, user).then(res => res);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const deleteUser = async (apiKey, userId) => {
|
|
22
|
+
return requests.deleteRequestHandler(Endpoints.deleteUser(userId), apiKey).then(res => res);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getUser = async (apiKey, params) => {
|
|
26
|
+
return requests.getRequestHandler(Endpoints.getUser, apiKey, params).then(res => res);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getAllUsers = async (apiKey, params) => {
|
|
30
|
+
return requests.getRequestHandler(Endpoints.getAllUsers, apiKey, params).then(res => res);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = { createUser, updateUser, deleteUser, getUser, getAllUsers };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const { validateType } = require('../../../common/validations/typeValidations');
|
|
2
|
+
const { ApiUserModel } = require('./user.model');
|
|
3
|
+
const usersApi = require('./users.api');
|
|
4
|
+
const httpResponseStatusCodes = require('../../../../../../packages/test-infra/src/common/httpResponseStatusCodes.json');
|
|
5
|
+
|
|
6
|
+
const createUser = async (apiKey, user) => {
|
|
7
|
+
validateType(user, ApiUserModel);
|
|
8
|
+
const response = await usersApi.createUser(apiKey, user);
|
|
9
|
+
validateResponse(response, httpResponseStatusCodes.OK, 'Create user has failed');
|
|
10
|
+
return response.data;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const updateUser = async (apiKey, user, userId) => {
|
|
14
|
+
const response = await usersApi.updateUser(apiKey, user, userId);
|
|
15
|
+
validateResponse(response, httpResponseStatusCodes.OK, 'Update user has failed');
|
|
16
|
+
return response.data;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const deleteUser = async (apiKey, userId) => {
|
|
20
|
+
const response = await usersApi.deleteUser(apiKey, userId);
|
|
21
|
+
validateResponse(response, httpResponseStatusCodes.OK, 'Delete user has failed');
|
|
22
|
+
return response.data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getUserByEmailId = async (apiKey, email) => {
|
|
26
|
+
const response = await usersApi.getUser(apiKey, { email });
|
|
27
|
+
return response;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getAllUsers = async (apiKey, { before, after, propertyId } = {}) => {
|
|
31
|
+
const response = await usersApi.getAllUsers(apiKey, { before, after, propertyId });
|
|
32
|
+
return response;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const validateResponse = (response, expectedStatus, errorMessage) => {
|
|
36
|
+
if (response.status !== expectedStatus) {
|
|
37
|
+
throw new Error(`${errorMessage}\n${JSON.stringify(response.status)}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = { createUser, updateUser, deleteUser, getUserByEmailId, getAllUsers };
|