@getjones/test-infra 1.0.9 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getjones/test-infra",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Providing internal and openapi interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -8,10 +8,16 @@ const init = conf => {
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
-
12
11
  const projects = require('./internal-api/projects/projects.setup');
13
12
 
14
- const accounts = { accountsCore, accountsSettings, accountsOpenAPI, ...accountsCore };
13
+ const accounts = {
14
+ core: accountsCore,
15
+ settings: accountsSettings,
16
+ openAPI: accountsOpenAPI,
17
+ accountsCore,
18
+ accountsSettings,
19
+ accountsOpenAPI
20
+ };
15
21
 
16
22
  const internalAPI = { auth, accounts, projects };
17
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 await requests.getRequestHandler(Endpoints.getAccount, params, context).then(res => res.data);
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;
@@ -2,11 +2,26 @@ const requests = require('../../common/requests');
2
2
  const { backendUrl } = require('../../../env').getEnv();
3
3
 
4
4
  const Endpoints = {
5
- assignApiKey: accountId => `${backendUrl}/saas/accounts/${accountId}/api-keys`,
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`
6
9
  };
7
10
 
8
- const assignApiKey = async (accountId, data, context) => {
9
- return requests.postRequestHandler(Endpoints.assignApiKey(accountId), data, context).then(res => res.data);
11
+ const assignApiKey = async (data, context) => {
12
+ return requests.postRequestHandler(Endpoints.assignApiKey, data, context).then(res => res.data);
10
13
  };
11
14
 
12
- module.exports = { assignApiKey };
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 };
@@ -1,27 +1,37 @@
1
1
  const accountsAPI = require('./accounts.openapi.api');
2
- const { apiKey } = require('../../../../../../src/accounts/openapi/test.config');
3
2
 
4
- const assignApiKey = async (accountId, apiKey, context) => {
5
- const data = { 'apiKey': apiKey };
6
- return accountsAPI.assignApiKey(accountId, data, context);
3
+ const assignApiKey = async (accountId, apiKeyValue, context) => {
4
+ const data = { apiKeyValue, accountId };
5
+ return accountsAPI.assignApiKey(data, context);
7
6
  };
8
7
 
9
8
  const getApiKeyByAccountId = async (accountId, context) => {
10
-
9
+ return accountsAPI.getApiKeyByAccountId(accountId, context);
11
10
  };
12
11
 
13
- const removeApiKey = async (accountId, context) => {
12
+ const getApiKeyDetails = async (apiKeyValue, context) => {
13
+ return accountsAPI.getApiKeyDetails(apiKeyValue, context);
14
+ };
14
15
 
16
+ const deleteApiKey = async (apiKeyValue, context) => {
17
+ const data = { apiKeyValue };
18
+ return accountsAPI.deleteApiKey(data, context);
15
19
  };
16
20
 
17
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
+ }
18
27
 
28
+ return existingApiKey;
19
29
  };
20
30
 
21
31
  module.exports = {
22
32
  assignApiKey,
23
33
  getApiKeyByAccountId,
24
- removeApiKey,
34
+ getApiKeyDetails,
35
+ deleteApiKey,
25
36
  getOrAssignApiKey
26
- };
27
-
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
- throw Error(JSON.stringify(error.response.data));
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
- throw Error(JSON.stringify(error.response.data));
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
- throw Error(JSON.stringify(error.response.data));
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
- throw Error(JSON.stringify(error.response.data));
45
+ const message = error.response.data && JSON.stringify(error.response.data) || error.message;
46
+ throw Error(message);
43
47
  }
44
48
 
45
49
  };