@getjones/test-infra 1.0.10 → 1.0.11
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/index.js +9 -2
- package/src/internal-api/accounts/core/accounts.core.api.js +1 -1
- package/src/internal-api/accounts/core/accounts.core.setup.js +1 -1
- package/src/internal-api/accounts/openapi/accounts.openapi.api.js +27 -0
- package/src/internal-api/accounts/openapi/accounts.openapi.setup.js +37 -0
- package/src/internal-api/common/requests.js +10 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -7,10 +7,17 @@ const init = conf => {
|
|
|
7
7
|
|
|
8
8
|
const accountsCore = require('./internal-api/accounts/core/accounts.core.setup');
|
|
9
9
|
const accountsSettings = require('./internal-api/accounts/settings/settings.setup');
|
|
10
|
-
|
|
10
|
+
const accountsOpenAPI = require('./internal-api/accounts/openapi/accounts.openapi.setup');
|
|
11
11
|
const projects = require('./internal-api/projects/projects.setup');
|
|
12
12
|
|
|
13
|
-
const accounts = {
|
|
13
|
+
const accounts = {
|
|
14
|
+
core: accountsCore,
|
|
15
|
+
settings: accountsSettings,
|
|
16
|
+
openAPI: accountsOpenAPI,
|
|
17
|
+
accountsCore,
|
|
18
|
+
accountsSettings,
|
|
19
|
+
accountsOpenAPI
|
|
20
|
+
};
|
|
14
21
|
|
|
15
22
|
const internalAPI = { auth, accounts, projects };
|
|
16
23
|
return { internalAPI };
|
|
@@ -22,7 +22,7 @@ const updateAccountSettings = async (accountId, settings, context) => {
|
|
|
22
22
|
|
|
23
23
|
const getByName = async (accountName, context) => {
|
|
24
24
|
const params = { name: accountName };
|
|
25
|
-
return
|
|
25
|
+
return requests.getRequestHandler(Endpoints.getAccount, params, context).then(res => res.data);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
module.exports = { create, getByName, deleteAccount, updateAccountSettings };
|
|
@@ -53,7 +53,7 @@ const getAccountId = async (accountName, context) => {
|
|
|
53
53
|
const account = await getAccount(accountName, context);
|
|
54
54
|
|
|
55
55
|
if (!account) {
|
|
56
|
-
throw NotFoundError(`Account ${accountName} does not exist`);
|
|
56
|
+
throw new NotFoundError(`Account ${accountName} does not exist`);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return account.userId;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const requests = require('../../common/requests');
|
|
2
|
+
const { backendUrl } = require('../../../env').getEnv();
|
|
3
|
+
|
|
4
|
+
const Endpoints = {
|
|
5
|
+
assignApiKey: `${backendUrl}/saas/api-keys`,
|
|
6
|
+
getApiKeyByAccountId: accountId => `${backendUrl}/saas/accounts/${accountId}/api-keys`,
|
|
7
|
+
getApiKeyDetails: `${backendUrl}/saas/api-keys`,
|
|
8
|
+
removeApiKey: `${backendUrl}/saas/api-keys`
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const assignApiKey = async (data, context) => {
|
|
12
|
+
return requests.postRequestHandler(Endpoints.assignApiKey, data, context).then(res => res.data);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getApiKeyByAccountId = async (accountId, context) => {
|
|
16
|
+
return requests.getRequestHandler(Endpoints.getApiKeyByAccountId(accountId), {}, context).then(res => res.data);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getApiKeyDetails = async (apiKeyValue, context) => {
|
|
20
|
+
return requests.getRequestHandler(Endpoints.getApiKeyDetails, { apiKeyValue }, context).then(res => res.data);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const deleteApiKey = async (data, context) => {
|
|
24
|
+
return requests.deleteRequestHandler(Endpoints.removeApiKey, context, {}, {}, data);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = { assignApiKey, getApiKeyByAccountId, getApiKeyDetails, deleteApiKey };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const accountsAPI = require('./accounts.openapi.api');
|
|
2
|
+
|
|
3
|
+
const assignApiKey = async (accountId, apiKeyValue, context) => {
|
|
4
|
+
const data = { apiKeyValue, accountId };
|
|
5
|
+
return accountsAPI.assignApiKey(data, context);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const getApiKeyByAccountId = async (accountId, context) => {
|
|
9
|
+
return accountsAPI.getApiKeyByAccountId(accountId, context);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getApiKeyDetails = async (apiKeyValue, context) => {
|
|
13
|
+
return accountsAPI.getApiKeyDetails(apiKeyValue, context);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const deleteApiKey = async (apiKeyValue, context) => {
|
|
17
|
+
const data = { apiKeyValue };
|
|
18
|
+
return accountsAPI.deleteApiKey(data, context);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getOrAssignApiKey = async (accountId, apiKey, context) => {
|
|
22
|
+
const existingApiKey = await getApiKeyByAccountId(accountId, context);
|
|
23
|
+
|
|
24
|
+
if (!existingApiKey.apiKey) {
|
|
25
|
+
return assignApiKey(accountId, apiKey, context);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return existingApiKey;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
assignApiKey,
|
|
33
|
+
getApiKeyByAccountId,
|
|
34
|
+
getApiKeyDetails,
|
|
35
|
+
deleteApiKey,
|
|
36
|
+
getOrAssignApiKey
|
|
37
|
+
};
|
|
@@ -6,7 +6,8 @@ const getRequestHandler = async (url, params = {}, context = null, headers = {})
|
|
|
6
6
|
const response = await axios.get(url, { params, headers });
|
|
7
7
|
return response;
|
|
8
8
|
} catch (error) {
|
|
9
|
-
|
|
9
|
+
const message = error.response.data && JSON.stringify(error.response.data) || error.message;
|
|
10
|
+
throw Error(message);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
};
|
|
@@ -17,7 +18,8 @@ const postRequestHandler = async (url, body, context = null, headers = {}) => {
|
|
|
17
18
|
const response = await axios.post(url, body, { headers });
|
|
18
19
|
return response;
|
|
19
20
|
} catch (error) {
|
|
20
|
-
|
|
21
|
+
const message = error.response.data && JSON.stringify(error.response.data) || error.message;
|
|
22
|
+
throw Error(message);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
};
|
|
@@ -28,18 +30,20 @@ const putRequestHandler = async (url, body, context = null, headers = {}) => {
|
|
|
28
30
|
const response = await axios.put(url, body, { headers });
|
|
29
31
|
return response;
|
|
30
32
|
} catch (error) {
|
|
31
|
-
|
|
33
|
+
const message = error.response.data && JSON.stringify(error.response.data) || error.message;
|
|
34
|
+
throw Error(message);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
};
|
|
35
38
|
|
|
36
|
-
const deleteRequestHandler = async (url, context = null, headers = {}, params = {}) => {
|
|
39
|
+
const deleteRequestHandler = async (url, context = null, headers = {}, params = {}, data = {}) => {
|
|
37
40
|
enrichCookie(headers, context);
|
|
38
41
|
try {
|
|
39
|
-
const response = await axios.delete(url, { params, headers });
|
|
42
|
+
const response = await axios.delete(url, { params, headers, data });
|
|
40
43
|
return response;
|
|
41
44
|
} catch (error) {
|
|
42
|
-
|
|
45
|
+
const message = error.response.data && JSON.stringify(error.response.data) || error.message;
|
|
46
|
+
throw Error(message);
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
};
|