@getjones/test-infra 1.2.5 → 1.2.7
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/requests/apiKeyAuth/requests.js +38 -0
- package/src/common/requests/cookieAuth/requests.js +40 -0
- package/src/common/requests/requestHandlers.js +60 -0
- package/src/common/validations/errorValidation.js +10 -10
- package/src/common/validations/typeValidations.js +4 -4
- package/src/index.js +7 -3
- package/src/saas/internal-api/accounts/api/core/accounts.core.api.js +14 -14
- package/src/saas/internal-api/accounts/api/core/accounts.core.setup.js +36 -36
- package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.api.js +27 -27
- package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.setup.js +35 -35
- package/src/saas/internal-api/accounts/api/settings/settings.api.js +8 -8
- package/src/saas/internal-api/accounts/api/settings/settings.setup.js +9 -9
- package/src/saas/internal-api/accounts/index.js +4 -4
- package/src/saas/internal-api/accounts/models/core/create.account.model.js +8 -9
- package/src/saas/internal-api/accounts/models/settings/update.settings.model.js +11 -11
- package/src/saas/internal-api/auth/api/auth.api.js +4 -4
- package/src/saas/internal-api/auth/api/auth.setup.js +31 -22
- package/src/saas/internal-api/auth/index.js +1 -1
- package/src/saas/internal-api/coi/api/coi.api.js +14 -14
- package/src/saas/internal-api/coi/api/coi.setup.js +5 -5
- package/src/saas/internal-api/coi/index.js +1 -1
- package/src/saas/internal-api/coi/models/submit.coi.model.js +6 -6
- package/src/saas/internal-api/compliance/api/audit/audit.api.js +11 -11
- package/src/saas/internal-api/compliance/api/audit/audit.setup.js +5 -5
- package/src/saas/internal-api/compliance/api/convert/convert.api.js +6 -6
- package/src/saas/internal-api/compliance/api/convert/convert.setup.js +3 -3
- package/src/saas/internal-api/compliance/api/coverage/coverage.api.js +15 -15
- package/src/saas/internal-api/compliance/api/coverage/coverage.setup.js +9 -9
- package/src/saas/internal-api/compliance/api/waive/waive.api.js +9 -11
- package/src/saas/internal-api/compliance/api/waive/waive.setup.js +5 -5
- package/src/saas/internal-api/compliance/index.js +15 -6
- package/src/saas/internal-api/compliance/models/audit/audit.model.js +66 -66
- package/src/saas/internal-api/compliance/models/waive/waive.model.js +28 -28
- package/src/saas/internal-api/contractors/api/contractors.api.js +42 -42
- package/src/saas/internal-api/contractors/api/contractors.setup.js +27 -27
- package/src/saas/internal-api/contractors/index.js +2 -2
- package/src/saas/internal-api/contractors/models/create.contractor.model.js +13 -13
- package/src/saas/internal-api/contractors/models/edit.contractor.model.js +66 -68
- package/src/saas/internal-api/globalRecord/api/global.record.api.js +46 -0
- package/src/saas/internal-api/globalRecord/api/global.record.setup.js +57 -0
- package/src/saas/internal-api/globalRecord/index.js +4 -0
- package/src/saas/internal-api/globalRecord/models/global.record.model.js +37 -0
- package/src/saas/internal-api/homepageCharts/api/charts.api.js +4 -4
- package/src/saas/internal-api/homepageCharts/api/charts.setup.js +2 -2
- package/src/saas/internal-api/homepageCharts/index.js +1 -1
- package/src/saas/internal-api/projects/api/core/projects.api.js +13 -13
- package/src/saas/internal-api/projects/api/core/projects.setup.js +26 -26
- package/src/saas/internal-api/projects/api/settings/project.settings.api.js +6 -6
- package/src/saas/internal-api/projects/api/settings/project.settings.setup.js +5 -5
- package/src/saas/internal-api/projects/index.js +5 -5
- package/src/saas/internal-api/projects/models/core/create.project.model.js +19 -19
- package/src/saas/internal-api/projects/models/core/update.project.model.js +21 -21
- package/src/saas/internal-api/projects/models/settings/update.project.settings.model.js +27 -28
- package/src/saas/internal-api/recordNotes/api/record.notes.api.js +18 -18
- package/src/saas/internal-api/recordNotes/api/record.notes.setup.js +11 -11
- package/src/saas/internal-api/reports/api/reports.api.js +4 -4
- package/src/saas/internal-api/reports/api/reports.setup.js +2 -3
- package/src/saas/internal-api/reports/index.js +3 -3
- package/src/saas/internal-api/reports/models/report.model.js +23 -23
- package/src/saas/internal-api/requirements/api/requirements.api.js +11 -11
- package/src/saas/internal-api/requirements/api/requirements.setup.js +7 -7
- package/src/saas/internal-api/requirements/index.js +1 -1
- package/src/saas/internal-api/requirements/models/create.requirement.model.js +27 -28
- package/src/saas/internal-api/tabs/api/tabs.api.js +1 -1
- package/src/saas/internal-api/tabs/index.js +1 -1
- package/src/saas/internal-api/thread-scheduler/runner.js +17 -0
- package/src/saas/internal-api/users/api/users.api.js +9 -9
- package/src/saas/internal-api/users/models/edit.user.model.js +6 -6
- package/src/saas/internal-api/vendorProfile/api/vendor.profile.api.js +1 -1
- package/src/saas/openapi/accounts/accounts.api.js +5 -5
- package/src/saas/openapi/accounts/accounts.setup.js +4 -4
- package/src/saas/openapi/contractors/contractors.api.js +3 -3
- package/src/saas/openapi/contractors/contractors.setup.js +5 -5
- package/src/saas/openapi/projects/projects.api.js +25 -24
- package/src/saas/openapi/projects/projects.setup.js +15 -15
- package/src/saas/openapi/requirements/index.js +1 -1
- package/src/saas/openapi/requirements/models/copy.requirement.model.js +7 -7
- package/src/saas/openapi/requirements/requirements.api.js +3 -4
- package/src/saas/openapi/requirements/requirements.setup.js +11 -11
- package/src/saas/openapi/tabs/tabs.api.js +4 -4
- package/src/saas/openapi/tabs/tabs.setup.js +2 -2
- package/src/saas/internal-api/common/requests.js +0 -71
- package/src/saas/openapi/common/requests.js +0 -74
- package/src/saas/thread-scheduler/runner.js +0 -17
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const requestHandler = require('./../requestHandlers');
|
|
2
|
+
|
|
3
|
+
const getRequestHandler = (url, apiKey, params = {}, headers = {}) => {
|
|
4
|
+
enrichApiKey(headers, apiKey);
|
|
5
|
+
return requestHandler.getRequestHandler(url, headers, params);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const postRequestHandler = (url, apiKey, body, headers = {}, params = {}) => {
|
|
9
|
+
enrichApiKey(headers, apiKey);
|
|
10
|
+
return requestHandler.postRequestHandler(url, body, headers, params);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const putRequestHandler = (url, apiKey, body, headers = {}, params = {}) => {
|
|
14
|
+
enrichApiKey(headers, apiKey);
|
|
15
|
+
return requestHandler.putRequestHandler(url, body, headers, params);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const patchRequestHandler = (url, apiKey, body, headers = {}) => {
|
|
19
|
+
enrichApiKey(headers, apiKey);
|
|
20
|
+
return requestHandler.patchRequestHandler(url, body, headers);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const deleteRequestHandler = (url, apiKey, headers = {}, params = {}, data = {}) => {
|
|
24
|
+
enrichApiKey(headers, apiKey);
|
|
25
|
+
return requestHandler.deleteRequestHandler(url, headers, params, data);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const enrichApiKey = (headers, apiKey) => {
|
|
29
|
+
headers['x-api-key'] = apiKey;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
getRequestHandler,
|
|
34
|
+
postRequestHandler,
|
|
35
|
+
putRequestHandler,
|
|
36
|
+
patchRequestHandler,
|
|
37
|
+
deleteRequestHandler
|
|
38
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const requestHandler = require('./../requestHandlers');
|
|
2
|
+
|
|
3
|
+
const getRequestHandler = (url, params = {}, context = null, headers = {}) => {
|
|
4
|
+
enrichCookie(headers, context);
|
|
5
|
+
return requestHandler.getRequestHandler(url, headers, params);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const postRequestHandler = (url, body, context = null, headers = {}, params = {}) => {
|
|
9
|
+
enrichCookie(headers, context);
|
|
10
|
+
return requestHandler.postRequestHandler(url, body, headers, params);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const putRequestHandler = (url, body, context = null, headers = {}, params = {}) => {
|
|
14
|
+
enrichCookie(headers, context);
|
|
15
|
+
return requestHandler.putRequestHandler(url, body, headers, params);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const patchRequestHandler = (url, context, body, headers = {}) => {
|
|
19
|
+
enrichCookie(headers, context);
|
|
20
|
+
return requestHandler.patchRequestHandler(url, body, headers);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const deleteRequestHandler = (url, context = null, headers = {}, params = {}, data = {}) => {
|
|
24
|
+
enrichCookie(headers, context);
|
|
25
|
+
return requestHandler.deleteRequestHandler(url, headers, params, data);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const enrichCookie = (headers, context) => {
|
|
29
|
+
if (context) {
|
|
30
|
+
headers.Cookie = context;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
getRequestHandler,
|
|
36
|
+
postRequestHandler,
|
|
37
|
+
putRequestHandler,
|
|
38
|
+
patchRequestHandler,
|
|
39
|
+
deleteRequestHandler
|
|
40
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const errorValidation = require('../validations/errorValidation');
|
|
3
|
+
|
|
4
|
+
const getRequestHandler = async (url, headers = {}, params = {}) => {
|
|
5
|
+
try {
|
|
6
|
+
const response = await axios.get(url, { params, headers });
|
|
7
|
+
return response;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
errorValidation.validateClientErrorResponseStatus(error);
|
|
10
|
+
return error.response;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const postRequestHandler = async (url, body, headers = {}, params = {}) => {
|
|
15
|
+
try {
|
|
16
|
+
const response = await axios.post(url, body, { headers, params });
|
|
17
|
+
return response;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
errorValidation.validateClientErrorResponseStatus(error);
|
|
20
|
+
return error.response;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const putRequestHandler = async (url, body, headers = {}, params = {}) => {
|
|
25
|
+
try {
|
|
26
|
+
const response = await axios.put(url, body, { headers, params });
|
|
27
|
+
return response;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
errorValidation.validateClientErrorResponseStatus(error);
|
|
30
|
+
return error.response;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const patchRequestHandler = async (url, body, headers = {}) => {
|
|
35
|
+
try {
|
|
36
|
+
const response = await axios.patch(url, body, { headers });
|
|
37
|
+
return response;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
errorValidation.validateClientErrorResponseStatus(error);
|
|
40
|
+
return error.response;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const deleteRequestHandler = async (url, headers = {}, params = {}, data = {}) => {
|
|
45
|
+
try {
|
|
46
|
+
const response = await axios.delete(url, { params, headers, data });
|
|
47
|
+
return response;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
errorValidation.validateClientErrorResponseStatus(error);
|
|
50
|
+
return error.response;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
getRequestHandler,
|
|
56
|
+
postRequestHandler,
|
|
57
|
+
putRequestHandler,
|
|
58
|
+
patchRequestHandler,
|
|
59
|
+
deleteRequestHandler
|
|
60
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const
|
|
1
|
+
const httpResponseStatusCodes = require('../httpResponseStatusCodes.json');
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const validateClientErrorResponseStatus = error => {
|
|
4
|
+
if (!error.response || !isResponseStatusClientErrorCode(error.response.status)) {
|
|
5
|
+
throw error;
|
|
6
|
+
}
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const isResponseStatusClientErrorCode = httpResponseStatusCode => {
|
|
10
|
+
const minClientErrorCode = httpResponseStatusCodes.BAD_REQUEST;
|
|
11
|
+
const maxClientErrorCode = httpResponseStatusCodes.CLIENT_CLOSED_REQUEST;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
return httpResponseStatusCode >= minClientErrorCode && httpResponseStatusCode <= maxClientErrorCode;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
module.exports = {
|
|
16
|
+
module.exports = { validateClientErrorResponseStatus };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const validateType = (input, expectedType) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
if (!(input instanceof expectedType)) {
|
|
3
|
+
throw TypeError(`Type should be: ${expectedType}`);
|
|
4
|
+
}
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
module.exports = { validateType };
|
|
7
|
+
module.exports = { validateType };
|
package/src/index.js
CHANGED
|
@@ -4,9 +4,8 @@ const init = conf => {
|
|
|
4
4
|
env.init(conf);
|
|
5
5
|
const internalAPI = getInternalAPI();
|
|
6
6
|
const openAPI = getOpenAPI();
|
|
7
|
-
const threadScheduler = require('./saas/thread-scheduler/runner');
|
|
8
7
|
|
|
9
|
-
return { internalAPI, openAPI
|
|
8
|
+
return { internalAPI, openAPI };
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
const getInternalAPI = () => {
|
|
@@ -26,6 +25,9 @@ const getInternalAPI = () => {
|
|
|
26
25
|
const reports = require('./saas/internal-api/reports');
|
|
27
26
|
const charts = require('./saas/internal-api/homepageCharts');
|
|
28
27
|
|
|
28
|
+
const globalRecord = require('./saas/internal-api/globalRecord');
|
|
29
|
+
|
|
30
|
+
const threadScheduler = require('./saas/internal-api/thread-scheduler/runner');
|
|
29
31
|
|
|
30
32
|
const internalAPI = {
|
|
31
33
|
auth,
|
|
@@ -38,7 +40,9 @@ const getInternalAPI = () => {
|
|
|
38
40
|
compliance,
|
|
39
41
|
reports,
|
|
40
42
|
users,
|
|
41
|
-
charts
|
|
43
|
+
charts,
|
|
44
|
+
globalRecord,
|
|
45
|
+
threadScheduler
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
return internalAPI;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
const requests = require('
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
2
|
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
3
|
|
|
4
4
|
const Endpoints = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
getAccount: `${backendUrl}/saas/accounts`,
|
|
6
|
+
create: `${backendUrl}/saas/createaccount`,
|
|
7
|
+
delete: `${backendUrl}/saas/account`,
|
|
8
|
+
edit: accountId => `${backendUrl}/saas/account/${accountId}/settings`
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const create =
|
|
12
|
-
|
|
11
|
+
const create = (account, context) => {
|
|
12
|
+
return requests.postRequestHandler(Endpoints.create, account, context);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const deleteAccount =
|
|
16
|
-
|
|
15
|
+
const deleteAccount = (accountId, context) => {
|
|
16
|
+
return requests.deleteRequestHandler(Endpoints.delete, context, {}, { 'userId': accountId });
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const updateAccountSettings =
|
|
20
|
-
|
|
19
|
+
const updateAccountSettings = (accountId, settings, context) => {
|
|
20
|
+
return requests.putRequestHandler(Endpoints.edit(accountId), { accountId, ... settings }, context);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const getByName =
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const getByName = (accountName, context) => {
|
|
24
|
+
const params = { name: accountName };
|
|
25
|
+
return requests.getRequestHandler(Endpoints.getAccount, params, context);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
module.exports = { create, getByName, deleteAccount, updateAccountSettings };
|
|
@@ -6,67 +6,67 @@ const { validateType } = require('../../../../../common/validations/typeValidati
|
|
|
6
6
|
const { accountCreationSecret } = env.getEnv();
|
|
7
7
|
|
|
8
8
|
const createAccount = async (createAccountModel, context) => {
|
|
9
|
-
|
|
9
|
+
validateType(createAccountModel, CreateAccountModel);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
env.requiredValidation({
|
|
12
|
+
accountCreationSecret: accountCreationSecret,
|
|
13
|
+
'credentials.strongPassword': createAccountModel.password
|
|
14
|
+
});
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return accountsAPI.create(createAccountModel, context);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const getAccount = async (accountName, context) => {
|
|
20
|
-
|
|
20
|
+
const response = await accountsAPI.getByName(accountName, context);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (!response.data || !response.data.length) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (response.data.length > 1) {
|
|
27
|
+
throw new Error(`Got more than one account with the name: ${accountName}. IDs: ${existingAccounts.map(item => item.userId).join(', ')}`);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
return response.data[0];
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const getOrCreateAccount = async (createAccountModel, context) => {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
validateType(createAccountModel, CreateAccountModel);
|
|
35
|
+
const existingAccount = await getAccount(createAccountModel.companyName, context);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (existingAccount) {
|
|
38
|
+
return existingAccount;
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const newAccountResponse = await createAccount(createAccountModel, context);
|
|
42
|
+
return newAccountResponse.data;
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
const getAccountId = async (accountName, context) => {
|
|
45
|
-
|
|
46
|
+
const account = await getAccount(accountName, context);
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (!account) {
|
|
49
|
+
console.error(`Account ${accountName} does not exist`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
return account.userId;
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
const deleteAccountByName = async (accountName, context) => {
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const accountId = await getAccountId(accountName, context);
|
|
58
|
+
return accountsAPI.deleteAccount(accountId, context);
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
const deleteAccountById = async (accountId, context) => {
|
|
61
|
-
|
|
62
|
+
return accountsAPI.deleteAccount(accountId, context);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
module.exports = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
getAccount,
|
|
67
|
+
getOrCreateAccount,
|
|
68
|
+
getAccountId,
|
|
69
|
+
createAccount,
|
|
70
|
+
deleteAccountByName,
|
|
71
|
+
deleteAccountById
|
|
71
72
|
};
|
|
72
|
-
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
const requests = require('
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
2
|
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
3
|
|
|
4
4
|
const Endpoints = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
createApiKey: `${backendUrl}/saas/api-keys`,
|
|
6
|
+
getStaticApiKeyByAccountId: accountId => `${backendUrl}/saas/accounts/${accountId}/static-api-keys`,
|
|
7
|
+
getApiKeyByKeyValue: `${backendUrl}/saas/api-keys`,
|
|
8
|
+
removeStaticApiKey: accountId => `${backendUrl}/saas/accounts/${accountId}/static-api-keys`,
|
|
9
|
+
dynamicApiKey: accountId => `${backendUrl}/saas/accounts/${accountId}/dynamic-api-key`
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const createStaticApiKey =
|
|
13
|
-
|
|
12
|
+
const createStaticApiKey = (data, context) => {
|
|
13
|
+
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const createGeneratorApiKey =
|
|
17
|
-
|
|
16
|
+
const createGeneratorApiKey = (data, context) => {
|
|
17
|
+
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const getStaticApiKeyByAccountId =
|
|
21
|
-
|
|
20
|
+
const getStaticApiKeyByAccountId = (accountId, context) => {
|
|
21
|
+
return requests.getRequestHandler(Endpoints.getStaticApiKeyByAccountId(accountId), {}, context);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const getApiKeyDetails =
|
|
25
|
-
|
|
24
|
+
const getApiKeyDetails = (apiKeyValue, context) => {
|
|
25
|
+
return requests.getRequestHandler(Endpoints.getApiKeyByKeyValue, { apiKeyValue }, context);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const deleteStaticApiKey =
|
|
29
|
-
|
|
28
|
+
const deleteStaticApiKey = (accountId, context) => {
|
|
29
|
+
return requests.deleteRequestHandler(Endpoints.removeStaticApiKey(accountId), context);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
const deleteDynamicApiKey =
|
|
33
|
-
|
|
32
|
+
const deleteDynamicApiKey = (accountId, context) => {
|
|
33
|
+
return requests.deleteRequestHandler(Endpoints.dynamicApiKey(accountId), context);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const makeDynamicApiKeyExpired =
|
|
37
|
-
|
|
36
|
+
const makeDynamicApiKeyExpired = (accountId, context) => {
|
|
37
|
+
return requests.patchRequestHandler(Endpoints.dynamicApiKey(accountId), context, {});
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
module.exports = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
createStaticApiKey,
|
|
42
|
+
createGeneratorApiKey,
|
|
43
|
+
getStaticApiKeyByAccountId,
|
|
44
|
+
getApiKeyDetails,
|
|
45
|
+
makeDynamicApiKeyExpired,
|
|
46
|
+
deleteStaticApiKey,
|
|
47
|
+
deleteDynamicApiKey
|
|
48
48
|
};
|
|
@@ -2,73 +2,73 @@ const accountsAPI = require('./accounts.openapi.api');
|
|
|
2
2
|
const crypto = require('crypto');
|
|
3
3
|
|
|
4
4
|
const generateApiKeyValue = accountName => {
|
|
5
|
-
|
|
5
|
+
return crypto.createHash('sha256').update(accountName).digest('base64');
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
const createStaticApiKey = async (accountId, apiKeyValue, context, { apiKeyType = 'ACCOUNT_STATIC', apiKeyName = null } = {}) => {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const data = { accountId, apiKeyValue, apiKeyName, apiKeyType };
|
|
10
|
+
return accountsAPI.createStaticApiKey(data, context);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const createGeneratorApiKey = async (accountId, apiKeyValue, context, { apiKeyType = 'GENERATOR', apiKeyName = null } = {}) => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const data = { accountId, apiKeyValue, apiKeyName, apiKeyType };
|
|
15
|
+
return accountsAPI.createGeneratorApiKey(data, context);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const getStaticApiKeyByAccountId = async (accountId, context) => {
|
|
19
|
-
|
|
19
|
+
return accountsAPI.getStaticApiKeyByAccountId(accountId, context);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const getApiKeyDetails = async (apiKeyValue, context) => {
|
|
23
|
-
|
|
23
|
+
return accountsAPI.getApiKeyDetails(apiKeyValue, context);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const deleteStaticApiKey = async (accountId, context) => {
|
|
27
|
-
|
|
27
|
+
return accountsAPI.deleteStaticApiKey(accountId, context);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const getOrCreateStaticApiKey = async (accountId, apiKeyValue, context, { apiKeyType = 'ACCOUNT_STATIC', apiKeyName = null } = {}) => {
|
|
31
|
-
|
|
31
|
+
let response = await getStaticApiKeyByAccountId(accountId, context);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (response.data.apiKeyValue) {
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
response = await getApiKeyDetails(apiKeyValue, context);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (!response.data.apiKeyValue) {
|
|
40
|
+
response = await createStaticApiKey(accountId, apiKeyValue, context, { apiKeyType, apiKeyName });
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
return response.data;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const getOrCreateGeneratorApiKey = async (accountId, apiKeyValue, context, { apiKeyType = 'GENERATOR', apiKeyName = null } = {}) => {
|
|
47
|
-
|
|
47
|
+
const existingApiKey = await getApiKeyDetails(apiKeyValue, context);
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!existingApiKey.apiKeyValue) {
|
|
50
|
+
return createGeneratorApiKey(accountId, apiKeyValue, context, { apiKeyType, apiKeyName });
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
return existingApiKey;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
const deleteDynamicApiKey= async (accountId, context) => {
|
|
57
|
-
|
|
56
|
+
const deleteDynamicApiKey = async (accountId, context) => {
|
|
57
|
+
return accountsAPI.deleteDynamicApiKey(accountId, context);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const makeDynamicApiKeyExpired= async (accountId, context) => {
|
|
61
|
-
|
|
60
|
+
const makeDynamicApiKeyExpired = async (accountId, context) => {
|
|
61
|
+
return accountsAPI.makeDynamicApiKeyExpired(accountId, context);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
module.exports = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
createStaticApiKey,
|
|
66
|
+
generateApiKeyValue,
|
|
67
|
+
getOrCreateStaticApiKey,
|
|
68
|
+
getOrCreateGeneratorApiKey,
|
|
69
|
+
getStaticApiKeyByAccountId,
|
|
70
|
+
getApiKeyDetails,
|
|
71
|
+
makeDynamicApiKeyExpired,
|
|
72
|
+
deleteStaticApiKey,
|
|
73
|
+
deleteDynamicApiKey
|
|
74
74
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const requests = require('
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
2
|
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
3
|
|
|
4
4
|
const Endpoints = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
get: accountId => `${backendUrl}/saas/account/${accountId}/settings`,
|
|
6
|
+
edit: accountId => `${backendUrl}/saas/account/${accountId}/settings`
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const getAccountSettings = async (accountId, context) => {
|
|
10
|
-
|
|
10
|
+
return requests.getRequestHandler(Endpoints.get(accountId), {}, context);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const updateAccountSettings = async (updateAccountSettingsModel, context) => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const { accountId } = updateAccountSettingsModel;
|
|
15
|
+
return requests.putRequestHandler(Endpoints.edit(accountId), updateAccountSettingsModel, context);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
module.exports = {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
getAccountSettings,
|
|
20
|
+
updateAccountSettings
|
|
21
21
|
};
|
|
@@ -3,21 +3,21 @@ const { validateType } = require('../../../../../common/validations/typeValidati
|
|
|
3
3
|
const UpdateAccountSettingsModel = require('../../models/settings/update.settings.model');
|
|
4
4
|
|
|
5
5
|
const getAccountSettings = async (accountId, context) => {
|
|
6
|
-
|
|
6
|
+
return accountsAPI.getAccountSettings(accountId, context).then(res => res.data);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const updateAccountSettings = async (updateAccountSettingsModel, context) => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
validateType(updateAccountSettingsModel, UpdateAccountSettingsModel);
|
|
11
|
+
return accountsAPI.updateAccountSettings(updateAccountSettingsModel, context);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const restoreAccountSettings = async (accountId, context) => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const updateAccountSettingsModel = new UpdateAccountSettingsModel(accountId, false, false, false);
|
|
16
|
+
return accountsAPI.updateAccountSettings(updateAccountSettingsModel, context);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
module.exports = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
20
|
+
getAccountSettings,
|
|
21
|
+
updateAccountSettings,
|
|
22
|
+
restoreAccountSettings
|
|
23
|
+
};
|
|
@@ -11,9 +11,9 @@ const openApiServices = require('./api/openapi/accounts.openapi.setup');
|
|
|
11
11
|
const settingsServices = require('./api/settings/settings.setup');
|
|
12
12
|
|
|
13
13
|
const services = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
core: coreService,
|
|
15
|
+
openApi: openApiServices,
|
|
16
|
+
settings: settingsServices
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
module.exports = { services, models };
|
|
19
|
+
module.exports = { services, models };
|
|
@@ -3,14 +3,13 @@ const { credentials, accountCreationSecret } = env.getEnv();
|
|
|
3
3
|
const PROPERTY_TYPE = 'Property Management';
|
|
4
4
|
|
|
5
5
|
function CreateAccountModel(accountName, email, password = credentials.strongPassword,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.userType = propertyType;
|
|
6
|
+
secret = accountCreationSecret, propertyType = PROPERTY_TYPE) {
|
|
7
|
+
this.companyName = accountName;
|
|
8
|
+
this.email = email;
|
|
9
|
+
this.password = password;
|
|
10
|
+
this.verifyPassword = password;
|
|
11
|
+
this.secret = secret;
|
|
12
|
+
this.userType = propertyType;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
module.exports = CreateAccountModel;
|
|
15
|
+
module.exports = CreateAccountModel;
|