@getjones/test-infra 1.2.4 → 1.2.6

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