@getjones/test-infra 1.8.1 → 1.11.0
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 +29 -29
- package/src/common/factory/index.js +3 -0
- package/src/common/factory/records/records.js +45 -0
- package/src/common/httpResponseStatusCodes.json +11 -11
- package/src/common/requests/apiKeyAuth/requests.js +38 -38
- package/src/common/requests/cookieAuth/requests.js +40 -40
- package/src/common/requests/requestHandlers.js +60 -60
- package/src/common/utils/numberUtils.js +22 -22
- package/src/common/utils/timeUtils.js +147 -0
- package/src/common/validations/errorValidation.js +16 -16
- package/src/common/validations/typeValidations.js +36 -36
- package/src/env.js +45 -44
- package/src/index.js +67 -65
- package/src/saas/internal-api/accounts/api/core/accounts.core.api.js +28 -28
- package/src/saas/internal-api/accounts/api/core/accounts.core.service.js +77 -77
- package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.api.js +48 -48
- package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.service.js +74 -74
- package/src/saas/internal-api/accounts/api/settings/settings.api.js +21 -21
- package/src/saas/internal-api/accounts/api/settings/settings.service.js +24 -24
- package/src/saas/internal-api/accounts/index.js +20 -20
- package/src/saas/internal-api/accounts/models/core/create.account.model.js +15 -15
- package/src/saas/internal-api/accounts/models/settings/update.settings.model.js +19 -19
- package/src/saas/internal-api/accounts/utils/utils.js +32 -32
- package/src/saas/internal-api/auth/api/auth.api.js +12 -12
- package/src/saas/internal-api/auth/api/auth.service.js +47 -47
- package/src/saas/internal-api/auth/index.js +3 -3
- package/src/saas/internal-api/coi/api/coi.api.js +34 -34
- package/src/saas/internal-api/coi/api/coi.service.js +22 -22
- package/src/saas/internal-api/coi/consts/uploaderTypes.js +7 -7
- package/src/saas/internal-api/coi/index.js +13 -13
- package/src/saas/internal-api/coi/models/submit.coi.model.js +9 -9
- package/src/saas/internal-api/coi/utils/utils.js +48 -48
- package/src/saas/internal-api/compliance/api/audit/audit.api.js +40 -40
- package/src/saas/internal-api/compliance/api/audit/audit.service.js +33 -33
- package/src/saas/internal-api/compliance/api/convert/convert.api.js +17 -17
- package/src/saas/internal-api/compliance/api/convert/convert.service.js +11 -11
- package/src/saas/internal-api/compliance/api/coverage/coverage.api.js +33 -33
- package/src/saas/internal-api/compliance/api/coverage/coverage.service.js +24 -24
- package/src/saas/internal-api/compliance/api/waive/waive.api.js +21 -21
- package/src/saas/internal-api/compliance/api/waive/waive.service.js +15 -15
- package/src/saas/internal-api/compliance/index.js +22 -22
- package/src/saas/internal-api/compliance/models/audit/audit.model.js +110 -110
- package/src/saas/internal-api/compliance/models/waive/waive.model.js +45 -45
- package/src/saas/internal-api/contractors/api/contractors.api.js +159 -121
- package/src/saas/internal-api/contractors/api/contractors.service.js +136 -101
- package/src/saas/internal-api/contractors/index.js +8 -8
- package/src/saas/internal-api/contractors/models/create.contractor.model.js +22 -22
- package/src/saas/internal-api/contractors/models/edit.contractor.model.js +69 -91
- package/src/saas/internal-api/contractors/models/verification.contractor.model.js +27 -33
- package/src/saas/internal-api/dbEmails/api/db.emails.api.js +25 -0
- package/src/saas/internal-api/dbEmails/api/db.emails.service.js +19 -0
- package/src/saas/internal-api/dbEmails/index.js +3 -0
- package/src/saas/internal-api/dbEmails/models/db.emails.model.js +21 -0
- package/src/saas/internal-api/globalRecord/api/global.record.api.js +76 -76
- package/src/saas/internal-api/globalRecord/api/global.record.service.js +83 -83
- package/src/saas/internal-api/globalRecord/consts.js +20 -20
- package/src/saas/internal-api/globalRecord/index.js +6 -6
- package/src/saas/internal-api/globalRecord/models/global.record.model.js +43 -43
- package/src/saas/internal-api/globalRecord/utils/util.js +148 -148
- package/src/saas/internal-api/homepageCharts/api/charts.api.js +12 -12
- package/src/saas/internal-api/homepageCharts/api/charts.service.js +7 -7
- package/src/saas/internal-api/homepageCharts/index.js +3 -3
- package/src/saas/internal-api/projects/api/core/projects.api.js +39 -39
- package/src/saas/internal-api/projects/api/core/projects.service.js +65 -65
- package/src/saas/internal-api/projects/api/settings/project.settings.api.js +18 -18
- package/src/saas/internal-api/projects/api/settings/project.settings.service.js +17 -17
- package/src/saas/internal-api/projects/consts/defaultProject.js +3 -3
- package/src/saas/internal-api/projects/index.js +24 -24
- package/src/saas/internal-api/projects/models/core/create.project.model.js +41 -41
- package/src/saas/internal-api/projects/models/core/update.project.model.js +47 -47
- package/src/saas/internal-api/projects/models/settings/update.project.settings.model.js +39 -39
- package/src/saas/internal-api/projects/utils/utils.js +82 -82
- package/src/saas/internal-api/recordNotes/api/record.notes.api.js +38 -38
- package/src/saas/internal-api/recordNotes/api/record.notes.service.js +29 -29
- package/src/saas/internal-api/recordNotes/index.js +3 -3
- package/src/saas/internal-api/reports/api/reports.api.js +39 -39
- package/src/saas/internal-api/reports/api/reports.service.js +34 -34
- package/src/saas/internal-api/reports/consts/consts.js +63 -63
- package/src/saas/internal-api/reports/index.js +15 -15
- package/src/saas/internal-api/reports/models/report.model.js +27 -27
- package/src/saas/internal-api/requests/api/requests.api.js +28 -0
- package/src/saas/internal-api/requests/api/requests.service.js +19 -0
- package/src/saas/internal-api/requests/index.js +11 -0
- package/src/saas/internal-api/requests/models/edit.request.model.js +31 -0
- package/src/saas/internal-api/requests/models/tenant.request.model.js +9 -0
- package/src/saas/internal-api/requests/models/validation.models.js +8 -0
- package/src/saas/internal-api/requirements/api/requirements.api.js +27 -27
- package/src/saas/internal-api/requirements/api/requirements.service.js +23 -23
- package/src/saas/internal-api/requirements/index.js +6 -6
- package/src/saas/internal-api/requirements/models/create.requirement.model.js +45 -45
- package/src/saas/internal-api/serviceArea/api/coordinates.api.js +12 -12
- package/src/saas/internal-api/serviceArea/api/coordinates.service.js +7 -7
- package/src/saas/internal-api/serviceArea/index.js +4 -4
- package/src/saas/internal-api/serviceArea/utils/utils.js +8 -8
- package/src/saas/internal-api/tabs/api/tabs.api.js +32 -32
- package/src/saas/internal-api/tabs/api/tabs.service.js +54 -54
- package/src/saas/internal-api/tabs/index.js +3 -3
- package/src/saas/internal-api/tabs/models/tabs.model.js +18 -18
- package/src/saas/internal-api/thread-scheduler/runner.js +13 -13
- package/src/saas/internal-api/users/api/users.api.js +78 -78
- package/src/saas/internal-api/users/api/users.service.js +101 -101
- package/src/saas/internal-api/users/index.js +4 -4
- package/src/saas/internal-api/users/models/users.model.js +31 -31
- package/src/saas/internal-api/users/utils/util.js +14 -14
- package/src/saas/internal-api/vendorProfile/api/vendor.profile.api.js +20 -20
- package/src/saas/internal-api/vendorProfile/api/vendor.profile.service.js +14 -14
- package/src/saas/internal-api/vendorProfile/index.js +3 -3
- package/src/saas/openapi/accounts/accounts.api.js +17 -17
- package/src/saas/openapi/accounts/accounts.service.js +11 -11
- package/src/saas/openapi/contractors/contractors.api.js +20 -20
- package/src/saas/openapi/contractors/contractors.service.js +18 -18
- package/src/saas/openapi/contractors/index.js +6 -6
- package/src/saas/openapi/contractors/models/invite.contractor.model.js +37 -37
- package/src/saas/openapi/projects/projects.api.js +59 -59
- package/src/saas/openapi/projects/projects.service.js +44 -44
- package/src/saas/openapi/requirements/index.js +6 -6
- package/src/saas/openapi/requirements/models/copy.requirement.model.js +10 -10
- package/src/saas/openapi/requirements/requirements.api.js +12 -12
- package/src/saas/openapi/requirements/requirements.service.js +20 -20
- package/src/saas/openapi/tabs/tabs.api.js +13 -13
- package/src/saas/openapi/tabs/tabs.service.js +7 -7
- package/tests/env.test.js +40 -40
- package/tests/validation.test.js +83 -83
- package/src/common/utils/dateUtils.js +0 -6
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
const validateType = (input, expectedType) => {
|
|
2
|
-
if (!(input instanceof expectedType)) {
|
|
3
|
-
throw TypeError(`Type should be: ${expectedType}`);
|
|
4
|
-
}
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const validateDateString = dateString => {
|
|
8
|
-
if (isNaN(Date.parse(dateString))) {
|
|
9
|
-
throw TypeError(`Invalid date string '${dateString}'`);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const validateInteger = (number, { min, max } = {}) => {
|
|
14
|
-
if (!Number.isInteger(number)) {
|
|
15
|
-
throw TypeError(`Invalid number '${number}'`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const exceedsMin = !isNaN(min) && number < min;
|
|
19
|
-
const exceedsMax = !isNaN(max) && number > max;
|
|
20
|
-
|
|
21
|
-
if (exceedsMin && exceedsMax) {
|
|
22
|
-
throw RangeError('Number is not in range.');
|
|
23
|
-
} else if (exceedsMin) {
|
|
24
|
-
throw RangeError(`Number is less than ${min}.`);
|
|
25
|
-
} else if (exceedsMax) {
|
|
26
|
-
throw RangeError(`Number is greater than ${max}.`);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const validateArray = obj => {
|
|
31
|
-
if (!Array.isArray(obj)) {
|
|
32
|
-
throw TypeError(`Invalid Array '${JSON.stringify(obj)}'`);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = { validateType, validateDateString, validateInteger, validateArray };
|
|
1
|
+
const validateType = (input, expectedType) => {
|
|
2
|
+
if (!(input instanceof expectedType)) {
|
|
3
|
+
throw TypeError(`Type should be: ${expectedType}`);
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const validateDateString = dateString => {
|
|
8
|
+
if (isNaN(Date.parse(dateString))) {
|
|
9
|
+
throw TypeError(`Invalid date string '${dateString}'`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const validateInteger = (number, { min, max } = {}) => {
|
|
14
|
+
if (!Number.isInteger(number)) {
|
|
15
|
+
throw TypeError(`Invalid number '${number}'`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const exceedsMin = !isNaN(min) && number < min;
|
|
19
|
+
const exceedsMax = !isNaN(max) && number > max;
|
|
20
|
+
|
|
21
|
+
if (exceedsMin && exceedsMax) {
|
|
22
|
+
throw RangeError('Number is not in range.');
|
|
23
|
+
} else if (exceedsMin) {
|
|
24
|
+
throw RangeError(`Number is less than ${min}.`);
|
|
25
|
+
} else if (exceedsMax) {
|
|
26
|
+
throw RangeError(`Number is greater than ${max}.`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const validateArray = obj => {
|
|
31
|
+
if (!Array.isArray(obj)) {
|
|
32
|
+
throw TypeError(`Invalid Array '${JSON.stringify(obj)}'`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = { validateType, validateDateString, validateInteger, validateArray };
|
package/src/env.js
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
let privateMembers = {
|
|
2
|
-
backendUrl: null,
|
|
3
|
-
openapiUrl: null,
|
|
4
|
-
nodeBackendUrl: null,
|
|
5
|
-
credentials: null,
|
|
6
|
-
environment: null,
|
|
7
|
-
accountCreationSecret: null,
|
|
8
|
-
threadSchedulerSecret: null,
|
|
9
|
-
nodeBackendSecret: null
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
let privateMembers = {
|
|
2
|
+
backendUrl: null,
|
|
3
|
+
openapiUrl: null,
|
|
4
|
+
nodeBackendUrl: null,
|
|
5
|
+
credentials: null,
|
|
6
|
+
environment: null,
|
|
7
|
+
accountCreationSecret: null,
|
|
8
|
+
threadSchedulerSecret: null,
|
|
9
|
+
nodeBackendSecret: null,
|
|
10
|
+
dbEmailsSecrets: null
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const init = conf => {
|
|
14
|
+
privateMembers = Object.assign(privateMembers, conf);
|
|
15
|
+
requiredValidation({
|
|
16
|
+
backendUrl: privateMembers.backendUrl,
|
|
17
|
+
openapiUrl: privateMembers.openapiUrl,
|
|
18
|
+
nodeBackendUrl: privateMembers.nodeBackendUrl,
|
|
19
|
+
environment: privateMembers.environment
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const requiredValidation = object => {
|
|
24
|
+
const invalidKeys = [];
|
|
25
|
+
Object.keys(object).forEach(key => {
|
|
26
|
+
if (!object[key]) {
|
|
27
|
+
invalidKeys.push(` '${key}'`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (invalidKeys.length > 0) {
|
|
32
|
+
throw Error(`Missing required configuration on your environment variables.\nThe missing env-vars are:${invalidKeys}`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const isLocalhost = () => {
|
|
37
|
+
return privateMembers.backendUrl.includes('localhost');
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
init,
|
|
42
|
+
getEnv: () => privateMembers,
|
|
43
|
+
requiredValidation,
|
|
44
|
+
isLocalhost
|
|
45
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
const env = require('./env');
|
|
2
|
-
|
|
3
|
-
const init = conf => {
|
|
4
|
-
env.init(conf);
|
|
5
|
-
const internalAPI = getInternalAPI();
|
|
6
|
-
const openAPI = getOpenAPI();
|
|
7
|
-
|
|
8
|
-
return { internalAPI, openAPI };
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const getInternalAPI = () => {
|
|
12
|
-
const auth = require('./saas/internal-api/auth');
|
|
13
|
-
const accounts = require('./saas/internal-api/accounts');
|
|
14
|
-
|
|
15
|
-
const projects = require('./saas/internal-api/projects');
|
|
16
|
-
const tabs = require('./saas/internal-api/tabs');
|
|
17
|
-
|
|
18
|
-
const requirements = require('./saas/internal-api/requirements');
|
|
19
|
-
const contractors = require('./saas/internal-api/contractors');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
const env = require('./env');
|
|
2
|
+
|
|
3
|
+
const init = conf => {
|
|
4
|
+
env.init(conf);
|
|
5
|
+
const internalAPI = getInternalAPI();
|
|
6
|
+
const openAPI = getOpenAPI();
|
|
7
|
+
|
|
8
|
+
return { internalAPI, openAPI };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getInternalAPI = () => {
|
|
12
|
+
const auth = require('./saas/internal-api/auth');
|
|
13
|
+
const accounts = require('./saas/internal-api/accounts');
|
|
14
|
+
|
|
15
|
+
const projects = require('./saas/internal-api/projects');
|
|
16
|
+
const tabs = require('./saas/internal-api/tabs');
|
|
17
|
+
|
|
18
|
+
const requirements = require('./saas/internal-api/requirements');
|
|
19
|
+
const contractors = require('./saas/internal-api/contractors');
|
|
20
|
+
const requests = require('./saas/internal-api/requests');
|
|
21
|
+
|
|
22
|
+
const coi = require('./saas/internal-api/coi');
|
|
23
|
+
const compliance = require('./saas/internal-api/compliance');
|
|
24
|
+
const users = require('./saas/internal-api/users');
|
|
25
|
+
|
|
26
|
+
const reports = require('./saas/internal-api/reports');
|
|
27
|
+
const charts = require('./saas/internal-api/homepageCharts');
|
|
28
|
+
|
|
29
|
+
const globalRecord = require('./saas/internal-api/globalRecord');
|
|
30
|
+
const vendorProfile = require('./saas/internal-api/vendorProfile');
|
|
31
|
+
const serviceArea = require('./saas/internal-api/serviceArea');
|
|
32
|
+
|
|
33
|
+
const threadScheduler = require('./saas/internal-api/thread-scheduler/runner');
|
|
34
|
+
|
|
35
|
+
const internalAPI = {
|
|
36
|
+
auth,
|
|
37
|
+
accounts,
|
|
38
|
+
projects,
|
|
39
|
+
tabs,
|
|
40
|
+
requirements,
|
|
41
|
+
contractors,
|
|
42
|
+
requests,
|
|
43
|
+
coi,
|
|
44
|
+
compliance,
|
|
45
|
+
reports,
|
|
46
|
+
users,
|
|
47
|
+
charts,
|
|
48
|
+
globalRecord,
|
|
49
|
+
vendorProfile,
|
|
50
|
+
serviceArea,
|
|
51
|
+
threadScheduler
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return internalAPI;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getOpenAPI = () => {
|
|
58
|
+
const accounts = require('./saas/openapi/accounts/accounts.service');
|
|
59
|
+
const tabs = require('./saas/openapi/tabs/tabs.service');
|
|
60
|
+
const contractors = require('./saas/openapi/contractors');
|
|
61
|
+
const projects = require('./saas/openapi/projects/projects.service');
|
|
62
|
+
const requirements = require('./saas/openapi/requirements');
|
|
63
|
+
const openAPI = { accounts, tabs, contractors, projects, requirements };
|
|
64
|
+
return openAPI;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
module.exports = init;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
|
-
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
-
|
|
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`
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const create = (account, context) => {
|
|
12
|
-
return requests.postRequestHandler(Endpoints.create, account, context);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const deleteAccount = (accountId, context) => {
|
|
16
|
-
return requests.deleteRequestHandler(Endpoints.delete, context, {}, { 'userId': accountId });
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const updateAccountSettings = (accountId, settings, context) => {
|
|
20
|
-
return requests.putRequestHandler(Endpoints.edit(accountId), { accountId, ... settings }, context);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const getByName = (accountName, context) => {
|
|
24
|
-
const params = { name: accountName };
|
|
25
|
-
return requests.getRequestHandler(Endpoints.getAccount, params, context);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = { create, getByName, deleteAccount, updateAccountSettings };
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
|
+
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
+
|
|
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`
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const create = (account, context) => {
|
|
12
|
+
return requests.postRequestHandler(Endpoints.create, account, context);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const deleteAccount = (accountId, context) => {
|
|
16
|
+
return requests.deleteRequestHandler(Endpoints.delete, context, {}, { 'userId': accountId });
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const updateAccountSettings = (accountId, settings, context) => {
|
|
20
|
+
return requests.putRequestHandler(Endpoints.edit(accountId), { accountId, ... settings }, context);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getByName = (accountName, context) => {
|
|
24
|
+
const params = { name: accountName };
|
|
25
|
+
return requests.getRequestHandler(Endpoints.getAccount, params, context);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = { create, getByName, deleteAccount, updateAccountSettings };
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
const env = require('../../../../../env');
|
|
2
|
-
const accountsAPI = require('./accounts.core.api');
|
|
3
|
-
const CreateAccountModel = require('../../models/core/create.account.model');
|
|
4
|
-
const { validateType } = require('../../../../../common/validations/typeValidations');
|
|
5
|
-
|
|
6
|
-
const { accountCreationSecret } = env.getEnv();
|
|
7
|
-
|
|
8
|
-
const createAccount = async (createAccountModel, context) => {
|
|
9
|
-
validateType(createAccountModel, CreateAccountModel);
|
|
10
|
-
|
|
11
|
-
env.requiredValidation({
|
|
12
|
-
accountCreationSecret: accountCreationSecret,
|
|
13
|
-
'credentials.strongPassword': createAccountModel.password
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return accountsAPI.create(createAccountModel, context);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const getAccount = async (accountName, context) => {
|
|
20
|
-
const response = await accountsAPI.getByName(accountName, context);
|
|
21
|
-
|
|
22
|
-
if (!response.data || !response.data.length) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
return response.data[0];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const getOrCreateAccount = async (createAccountModel, context) => {
|
|
34
|
-
validateType(createAccountModel, CreateAccountModel);
|
|
35
|
-
const existingAccount = await getAccount(createAccountModel.companyName, context);
|
|
36
|
-
|
|
37
|
-
if (existingAccount) {
|
|
38
|
-
return existingAccount;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const response = await accountsAPI.create(createAccountModel, context);
|
|
42
|
-
|
|
43
|
-
if (!response.data) {
|
|
44
|
-
throw new Error(`Account by the name ${createAccountModel.companyName} did not crate`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return response.data;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const getAccountId = async (accountName, context) => {
|
|
51
|
-
const account = await getAccount(accountName, context);
|
|
52
|
-
|
|
53
|
-
if (!account) {
|
|
54
|
-
console.error(`Account ${accountName} does not exist`);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return account.userId;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const deleteAccountByName = async (accountName, context) => {
|
|
62
|
-
const accountId = await getAccountId(accountName, context);
|
|
63
|
-
return accountsAPI.deleteAccount(accountId, context);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const deleteAccountById = async (accountId, context) => {
|
|
67
|
-
return accountsAPI.deleteAccount(accountId, context);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
getAccount,
|
|
72
|
-
getOrCreateAccount,
|
|
73
|
-
getAccountId,
|
|
74
|
-
createAccount,
|
|
75
|
-
deleteAccountByName,
|
|
76
|
-
deleteAccountById
|
|
77
|
-
};
|
|
1
|
+
const env = require('../../../../../env');
|
|
2
|
+
const accountsAPI = require('./accounts.core.api');
|
|
3
|
+
const CreateAccountModel = require('../../models/core/create.account.model');
|
|
4
|
+
const { validateType } = require('../../../../../common/validations/typeValidations');
|
|
5
|
+
|
|
6
|
+
const { accountCreationSecret } = env.getEnv();
|
|
7
|
+
|
|
8
|
+
const createAccount = async (createAccountModel, context) => {
|
|
9
|
+
validateType(createAccountModel, CreateAccountModel);
|
|
10
|
+
|
|
11
|
+
env.requiredValidation({
|
|
12
|
+
accountCreationSecret: accountCreationSecret,
|
|
13
|
+
'credentials.strongPassword': createAccountModel.password
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return accountsAPI.create(createAccountModel, context);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getAccount = async (accountName, context) => {
|
|
20
|
+
const response = await accountsAPI.getByName(accountName, context);
|
|
21
|
+
|
|
22
|
+
if (!response.data || !response.data.length) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
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
|
+
|
|
30
|
+
return response.data[0];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getOrCreateAccount = async (createAccountModel, context) => {
|
|
34
|
+
validateType(createAccountModel, CreateAccountModel);
|
|
35
|
+
const existingAccount = await getAccount(createAccountModel.companyName, context);
|
|
36
|
+
|
|
37
|
+
if (existingAccount) {
|
|
38
|
+
return existingAccount;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const response = await accountsAPI.create(createAccountModel, context);
|
|
42
|
+
|
|
43
|
+
if (!response.data) {
|
|
44
|
+
throw new Error(`Account by the name ${createAccountModel.companyName} did not crate`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return response.data;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getAccountId = async (accountName, context) => {
|
|
51
|
+
const account = await getAccount(accountName, context);
|
|
52
|
+
|
|
53
|
+
if (!account) {
|
|
54
|
+
console.error(`Account ${accountName} does not exist`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return account.userId;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const deleteAccountByName = async (accountName, context) => {
|
|
62
|
+
const accountId = await getAccountId(accountName, context);
|
|
63
|
+
return accountsAPI.deleteAccount(accountId, context);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const deleteAccountById = async (accountId, context) => {
|
|
67
|
+
return accountsAPI.deleteAccount(accountId, context);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
getAccount,
|
|
72
|
+
getOrCreateAccount,
|
|
73
|
+
getAccountId,
|
|
74
|
+
createAccount,
|
|
75
|
+
deleteAccountByName,
|
|
76
|
+
deleteAccountById
|
|
77
|
+
};
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
|
-
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
-
|
|
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`
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const createStaticApiKey = (data, context) => {
|
|
13
|
-
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const createGeneratorApiKey = (data, context) => {
|
|
17
|
-
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getStaticApiKeyByAccountId = (accountId, context) => {
|
|
21
|
-
return requests.getRequestHandler(Endpoints.getStaticApiKeyByAccountId(accountId), {}, context);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getApiKeyDetails = (apiKeyValue, context) => {
|
|
25
|
-
return requests.getRequestHandler(Endpoints.getApiKeyByKeyValue, { apiKeyValue }, context);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const deleteStaticApiKey = (accountId, context) => {
|
|
29
|
-
return requests.deleteRequestHandler(Endpoints.removeStaticApiKey(accountId), context);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const deleteDynamicApiKey = (accountId, context) => {
|
|
33
|
-
return requests.deleteRequestHandler(Endpoints.dynamicApiKey(accountId), context);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const makeDynamicApiKeyExpired = (accountId, context) => {
|
|
37
|
-
return requests.patchRequestHandler(Endpoints.dynamicApiKey(accountId), context, {});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
createStaticApiKey,
|
|
42
|
-
createGeneratorApiKey,
|
|
43
|
-
getStaticApiKeyByAccountId,
|
|
44
|
-
getApiKeyDetails,
|
|
45
|
-
makeDynamicApiKeyExpired,
|
|
46
|
-
deleteStaticApiKey,
|
|
47
|
-
deleteDynamicApiKey
|
|
48
|
-
};
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
|
+
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
+
|
|
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`
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const createStaticApiKey = (data, context) => {
|
|
13
|
+
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const createGeneratorApiKey = (data, context) => {
|
|
17
|
+
return requests.postRequestHandler(Endpoints.createApiKey, data, context);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getStaticApiKeyByAccountId = (accountId, context) => {
|
|
21
|
+
return requests.getRequestHandler(Endpoints.getStaticApiKeyByAccountId(accountId), {}, context);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getApiKeyDetails = (apiKeyValue, context) => {
|
|
25
|
+
return requests.getRequestHandler(Endpoints.getApiKeyByKeyValue, { apiKeyValue }, context);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const deleteStaticApiKey = (accountId, context) => {
|
|
29
|
+
return requests.deleteRequestHandler(Endpoints.removeStaticApiKey(accountId), context);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const deleteDynamicApiKey = (accountId, context) => {
|
|
33
|
+
return requests.deleteRequestHandler(Endpoints.dynamicApiKey(accountId), context);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const makeDynamicApiKeyExpired = (accountId, context) => {
|
|
37
|
+
return requests.patchRequestHandler(Endpoints.dynamicApiKey(accountId), context, {});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
createStaticApiKey,
|
|
42
|
+
createGeneratorApiKey,
|
|
43
|
+
getStaticApiKeyByAccountId,
|
|
44
|
+
getApiKeyDetails,
|
|
45
|
+
makeDynamicApiKeyExpired,
|
|
46
|
+
deleteStaticApiKey,
|
|
47
|
+
deleteDynamicApiKey
|
|
48
|
+
};
|