@stackfactor/client-api 1.0.0 → 1.0.2

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/index.js CHANGED
@@ -1,22 +1,47 @@
1
- export * from "./lib/actionNotifications";
2
- export * from "./lib/address";
3
- export * from "./lib/config";
4
- export * from "./lib/integration";
5
- export * from "./lib/integrationsConfiguration";
6
- export * from "./lib/departmentTraiingPlans";
7
- export * from "./lib/groups";
8
- export * from "./lib/role";
9
- export * from "./lib/roleTemplate";
10
- export * from "./lib/skill";
11
- export * from "./lib/skillAssessments";
12
- export * from "./lib/skillTemplate";
13
- export * from "./lib/teams";
14
- export * from "./lib/templateDocument";
15
- export * from "./lib/templatePhase";
16
- export * from "./lib/templateRelease";
17
- export * from "./lib/templates";
18
- export * from "./lib/tenants";
19
- export * from "./lib/trainingPlanTemplate";
20
- export * from "./lib/trainingPlans";
21
- export * from "./lib/userInformation";
22
- export * from "./lib/users";
1
+ const actionNotifications = require("./lib/actionNotifications");
2
+ const address = require("./lib/address");
3
+ const config = require("./lib/config");
4
+ const integration = require("./lib/integration");
5
+ const integrationsConfiguration = require("./lib/integrationsConfiguration");
6
+ const departmentTraiingPlans = require("./lib/departmentTraiingPlans");
7
+ const groups = require("./lib/groups");
8
+ const role = require("./lib/role");
9
+ const roleTemplate = require("./lib/roleTemplate");
10
+ const skill = require("./lib/skill");
11
+ const skillAssessments = require("./lib/skillAssessments");
12
+ const skillTemplate = require("./lib/skillTemplate");
13
+ const teams = require("./lib/teams");
14
+ const templateDocument = require("./lib/templateDocument");
15
+ const templatePhase = require("./lib/templatePhase");
16
+ const templateRelease = require("./lib/templateRelease");
17
+ const templates = require("./lib/templates");
18
+ const tenants = require("./lib/tenants");
19
+ const trainingPlanTemplate = require("./lib/trainingPlanTemplate");
20
+ const trainingPlans = require("./lib/trainingPlans");
21
+ const userInformation = require("./lib/userInformation");
22
+ const users = require("./lib/users");
23
+
24
+ module.exports = {
25
+ actionNotifications,
26
+ address,
27
+ config,
28
+ integration,
29
+ integrationsConfiguration,
30
+ departmentTraiingPlans,
31
+ groups,
32
+ role,
33
+ roleTemplate,
34
+ skill,
35
+ skillAssessments,
36
+ skillTemplate,
37
+ teams,
38
+ templateDocument,
39
+ templatePhase,
40
+ templateRelease,
41
+ templates,
42
+ tenants,
43
+ trainingPlanTemplate,
44
+ trainingPlans,
45
+ userInformation,
46
+ users,
47
+ };
@@ -1,16 +1,13 @@
1
- //
2
- // Notification sepcific requests
3
- //
4
- import axios from "./axios";
1
+ const axios = require("./axios");
5
2
 
6
- export default {
3
+ module.exports = {
7
4
  axios: axios,
8
5
 
9
6
  /**
10
7
  * Get all permissions
11
8
  * @param {String} authToken The authentication token
12
9
  */
13
- getAllUserNotifications(authToken) {
10
+ getAllUserNotifications: (authToken) => {
14
11
  return new Promise(function (resolve, reject) {
15
12
  const request = axios.get(`api/v1/actionnotifications`, {
16
13
  headers: { authorization: authToken },
@@ -27,11 +24,11 @@ export default {
27
24
 
28
25
  /**
29
26
  * Mark notifications as open or viewed
30
- * @param {*} ids The id of the notifications to be marked
31
- * @param {*} status The new status
32
- * @param {*} authToken The authentication token
27
+ * @param {Array<String>} ids The id of the notifications to be marked
28
+ * @param {String} status The new status
29
+ * @param {String} authToken The authentication token
33
30
  */
34
- markNotifications(ids, status, authToken) {
31
+ markNotifications: (ids, status, authToken) => {
35
32
  return new Promise(function (resolve, reject) {
36
33
  const request = axios.put(
37
34
  `api/v1/actionnotifications/mark`,
@@ -58,7 +55,7 @@ export default {
58
55
  * @param {String} comment The comment to be saved in the notification
59
56
  * @param {String} authToken The authentication token
60
57
  */
61
- processNotification(id, action, comment, authToken) {
58
+ processNotification: (id, action, comment, authToken) => {
62
59
  return new Promise(function (resolve, reject) {
63
60
  const request = axios.put(
64
61
  `api/v1/actionnotifications/process`,
@@ -81,9 +78,9 @@ export default {
81
78
 
82
79
  /**
83
80
  * Get groups for current tenant
84
- * @param {*} authToken The authentication token
81
+ * @param {String} authToken The authentication token
85
82
  */
86
- getGroups(authToken) {
83
+ getGroups: (authToken) => {
87
84
  return new Promise(function (resolve, reject) {
88
85
  const request = axios.get(`api/v1/groups/`, {
89
86
  headers: { authorization: authToken },
@@ -100,9 +97,9 @@ export default {
100
97
 
101
98
  /**
102
99
  * Get current user permissions
103
- * @param {*} authToken The authentication token
100
+ * @param {String} authToken The authentication token
104
101
  */
105
- getUserPermissions(authToken) {
102
+ getUserPermissions: (authToken) => {
106
103
  return new Promise(function (resolve, reject) {
107
104
  const request = axios.get(`api/v1/groups/users/getuserpermissions`, {
108
105
  headers: { authorization: authToken },
@@ -143,7 +140,7 @@ export default {
143
140
  * @param {Array<String>} permissions The permissions to be removed from the group
144
141
  * @param {String} authToken The authentication token
145
142
  */
146
- removePermissionsFromGroup(groupId, permissions, authToken) {
143
+ removePermissionsFromGroup: (groupId, permissions, authToken) => {
147
144
  return new Promise(function (resolve, reject) {
148
145
  const request = axios.post(
149
146
  `api/v1/groups/permissions/remove/`,
@@ -169,7 +166,7 @@ export default {
169
166
  * @param {Array<String>} users The users to be removed from the group
170
167
  * @param {String} authToken The authentication token
171
168
  */
172
- removeUsersFromGroup(groupId, users, authToken) {
169
+ removeUsersFromGroup: (groupId, users, authToken) => {
173
170
  return new Promise(function (resolve, reject) {
174
171
  const request = axios.post(
175
172
  `api/v1/groups/users/remove/`,
@@ -194,7 +191,7 @@ export default {
194
191
  * @param {String} groupId The group Id
195
192
  * @param {String} authToken The authentication token
196
193
  */
197
- setDefault(groupId, authToken) {
194
+ setDefault: (groupId, authToken) => {
198
195
  return new Promise(function (resolve, reject) {
199
196
  const request = axios.put(
200
197
  `api/v1/groups/setDefault/`,
@@ -220,7 +217,7 @@ export default {
220
217
  * @param {string} description The updated description of the group
221
218
  * @param {String} authToken The authentication token
222
219
  */
223
- updateGroup(groupId, name, description, authToken) {
220
+ updateGroup: (groupId, name, description, authToken) => {
224
221
  return new Promise(function (resolve, reject) {
225
222
  const request = axios.patch(
226
223
  `api/v1/groups/group/`,
package/lib/address.js CHANGED
@@ -1,6 +1,6 @@
1
- import axios from "./axios";
1
+ const axios = require("./axios");
2
2
 
3
- export default {
3
+ module.exports = {
4
4
  axios: axios,
5
5
 
6
6
  /**
@@ -10,7 +10,7 @@ export default {
10
10
  * @param {String} authToken - Authorization token
11
11
  *
12
12
  */
13
- autoComplete(input, authToken) {
13
+ autoComplete: (input, authToken) => {
14
14
  return new Promise(function (resolve, reject) {
15
15
  const getAddressesRequest = axios.post(
16
16
  `api/v1/address/autocomplete/`,
package/lib/axios.js CHANGED
@@ -1,5 +1,5 @@
1
- import axios from "axios";
2
- import utils from "./utils";
1
+ const axios = require("./axios");
2
+ const utils = require("./utils");
3
3
 
4
4
  const baseUrl = utils.getBaseUrl();
5
5
 
@@ -10,207 +10,207 @@ let instance = axios.create({
10
10
  /**
11
11
  * Server response type
12
12
  */
13
- export const responseType = {
14
- /**
15
- * The requested resource corresponds to any one of a set of representations, each with its own specific location.
16
- */
17
- MULTIPLE_CHOICES: 300,
18
- /**
19
- * The resource has moved permanently. Please refer to the documentation.
20
- */
21
- MOVED_PERMANENTLY: 301,
22
- /**
23
- * The resource has moved temporarily. Please refer to the documentation.
24
- */
25
- FOUND: 302,
26
- /**
27
- * The resource can be found under a different URI.
28
- */
29
- SEE_OTHER: 303,
30
- /**
31
- * The resource is available and not modified.
32
- */
33
- NOT_MODIFIED: 304,
34
- /**
35
- * The requested resource must be accessed through the proxy given by the Location field.
36
- */
37
- USE_PROXY: 305,
38
- /**
39
- * The resource resides temporarily under a different URI.
40
- */
41
- TEMPORARY_REDIRECT: 307,
42
- /**
43
- * Invalid syntax for this request was provided.
44
- */
45
- BAD_REQUEST: 400,
46
- /**
47
- * You are unauthorized to access the requested resource. Please log in.
48
- */
49
- UNAUTHORIZED: 401,
50
- /**
51
- * Your account is not authorized to access the requested resource.
52
- */
53
- FORBIDDEN: 403,
54
- /**
55
- * We could not find the resource you requested. Please refer to the documentation for the list of resources.
56
- */
57
- NOT_FOUND: 404,
58
- /**
59
- * This method type is not currently supported.
60
- */
61
- METHOD_NOT_ALLOWED: 405,
62
- /**
63
- * Acceptance header is invalid for this endpoint resource.
64
- */
65
- NOT_ACCEPTABLE: 406,
66
- /**
67
- * Authentication with proxy is required.
68
- */
69
- PROXY_AUTHENTICATION_REQUIRED: 407,
70
- /**
71
- * Client did not produce a request within the time that the server was prepared to wait.
72
- */
73
- REQUEST_TIMEOUT: 408,
74
- /**
75
- * The request could not be completed due to a conflict with the current state of the resource.
76
- */
77
- CONFLICT: 409,
78
- /**
79
- * The requested resource is no longer available and has been permanently removed.
80
- */
81
- GONE: 410,
82
- /**
83
- * Length of the content is required, please include it with the request.
84
- */
85
- LENGTH_REQUIRED: 411,
86
- /**
87
- * The request did not match the pre-conditions of the requested resource.
88
- */
89
- PRECONDITION_FAILED: 412,
90
- /**
91
- * The request entity is larger than the server is willing or able to process.
92
- */
93
- REQUEST_ENTITY_TOO_LARGE: 413,
94
- /**
95
- * The request URI is longer than the server is willing to interpret.
96
- */
97
- REQUEST_URI_TOO_LONG: 414,
98
- /**
99
- * The requested resource does not support the media type provided.
100
- */
101
- UNSUPPORTED_MEDIA_TYPE: 415,
102
- /**
103
- * The requested range for the resource is not available.
104
- */
105
- REQUESTED_RANGE_NOT_SATISFIABLE: 416,
106
- /**
107
- * Unable to meet the expectation given in the Expect request header.
108
- */
109
- EXPECTATION_FAILED: 417,
110
- /**
111
- * The requested resource is missing required arguments.
112
- */
113
- MISSING_ARGUMENTS: 419,
114
- /**
115
- * The requested resource does not support one or more of the given parameters.
116
- */
117
- INVALID_ARGUMENTS: 420,
118
- /**
119
- * The request was well-formed but was unable to be followed due to semantic errors.
120
- */
121
- UNPROCESSABLE_ENTITY: 422,
122
- /**
123
- * Unexpected internal server error.
124
- */
125
- INTERNAL_SERVER_ERROR: 500,
126
- /**
127
- * The requested resource is recognized but not implemented.
128
- */
129
- NOT_IMPLEMENTED: 501,
130
- /**
131
- * Invalid response received when acting as a proxy or gateway.
132
- */
133
- BAD_GATEWAY: 502,
13
+ module.exports = {
14
+ responseType: {
15
+ /**
16
+ * The requested resource corresponds to any one of a set of representations, each with its own specific location.
17
+ */
18
+ MULTIPLE_CHOICES: 300,
19
+ /**
20
+ * The resource has moved permanently. Please refer to the documentation.
21
+ */
22
+ MOVED_PERMANENTLY: 301,
23
+ /**
24
+ * The resource has moved temporarily. Please refer to the documentation.
25
+ */
26
+ FOUND: 302,
27
+ /**
28
+ * The resource can be found under a different URI.
29
+ */
30
+ SEE_OTHER: 303,
31
+ /**
32
+ * The resource is available and not modified.
33
+ */
34
+ NOT_MODIFIED: 304,
35
+ /**
36
+ * The requested resource must be accessed through the proxy given by the Location field.
37
+ */
38
+ USE_PROXY: 305,
39
+ /**
40
+ * The resource resides temporarily under a different URI.
41
+ */
42
+ TEMPORARY_REDIRECT: 307,
43
+ /**
44
+ * Invalid syntax for this request was provided.
45
+ */
46
+ BAD_REQUEST: 400,
47
+ /**
48
+ * You are unauthorized to access the requested resource. Please log in.
49
+ */
50
+ UNAUTHORIZED: 401,
51
+ /**
52
+ * Your account is not authorized to access the requested resource.
53
+ */
54
+ FORBIDDEN: 403,
55
+ /**
56
+ * We could not find the resource you requested. Please refer to the documentation for the list of resources.
57
+ */
58
+ NOT_FOUND: 404,
59
+ /**
60
+ * This method type is not currently supported.
61
+ */
62
+ METHOD_NOT_ALLOWED: 405,
63
+ /**
64
+ * Acceptance header is invalid for this endpoint resource.
65
+ */
66
+ NOT_ACCEPTABLE: 406,
67
+ /**
68
+ * Authentication with proxy is required.
69
+ */
70
+ PROXY_AUTHENTICATION_REQUIRED: 407,
71
+ /**
72
+ * Client did not produce a request within the time that the server was prepared to wait.
73
+ */
74
+ REQUEST_TIMEOUT: 408,
75
+ /**
76
+ * The request could not be completed due to a conflict with the current state of the resource.
77
+ */
78
+ CONFLICT: 409,
79
+ /**
80
+ * The requested resource is no longer available and has been permanently removed.
81
+ */
82
+ GONE: 410,
83
+ /**
84
+ * Length of the content is required, please include it with the request.
85
+ */
86
+ LENGTH_REQUIRED: 411,
87
+ /**
88
+ * The request did not match the pre-conditions of the requested resource.
89
+ */
90
+ PRECONDITION_FAILED: 412,
91
+ /**
92
+ * The request entity is larger than the server is willing or able to process.
93
+ */
94
+ REQUEST_ENTITY_TOO_LARGE: 413,
95
+ /**
96
+ * The request URI is longer than the server is willing to interpret.
97
+ */
98
+ REQUEST_URI_TOO_LONG: 414,
99
+ /**
100
+ * The requested resource does not support the media type provided.
101
+ */
102
+ UNSUPPORTED_MEDIA_TYPE: 415,
103
+ /**
104
+ * The requested range for the resource is not available.
105
+ */
106
+ REQUESTED_RANGE_NOT_SATISFIABLE: 416,
107
+ /**
108
+ * Unable to meet the expectation given in the Expect request header.
109
+ */
110
+ EXPECTATION_FAILED: 417,
111
+ /**
112
+ * The requested resource is missing required arguments.
113
+ */
114
+ MISSING_ARGUMENTS: 419,
115
+ /**
116
+ * The requested resource does not support one or more of the given parameters.
117
+ */
118
+ INVALID_ARGUMENTS: 420,
119
+ /**
120
+ * The request was well-formed but was unable to be followed due to semantic errors.
121
+ */
122
+ UNPROCESSABLE_ENTITY: 422,
123
+ /**
124
+ * Unexpected internal server error.
125
+ */
126
+ INTERNAL_SERVER_ERROR: 500,
127
+ /**
128
+ * The requested resource is recognized but not implemented.
129
+ */
130
+ NOT_IMPLEMENTED: 501,
131
+ /**
132
+ * Invalid response received when acting as a proxy or gateway.
133
+ */
134
+ BAD_GATEWAY: 502,
135
+ /**
136
+ * The server is currently unavailable.
137
+ */
138
+ SERVICE_UNAVAILABLE: 503,
139
+ /**
140
+ * Did not receive a timely response from upstream server while acting as a gateway or proxy.
141
+ */
142
+ GATEWAY_TIMEOUT: 504,
143
+ /**
144
+ * The HTTP protocol version used in the request message is not supported.
145
+ */
146
+ HTTP_VERSION_NOT_SUPPORTED: 505,
147
+ /**
148
+ * A failure occurred during initialization of services. API will be unavailable.
149
+ */
150
+ INITIALIZATION_FAILURE: 550,
151
+ },
152
+
134
153
  /**
135
- * The server is currently unavailable.
136
- */
137
- SERVICE_UNAVAILABLE: 503,
154
+ * Returns the error as a string
155
+ * @param {Object} error
156
+ */
157
+ errorToString: (error) => {
158
+ if (error != null) {
159
+ if (error?.response?.data) {
160
+ let asString = "";
161
+ if (Array.isArray(error.response.data.errors)) {
162
+ error.response.data.errors.forEach((item, index) => {
163
+ asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
164
+ item.param
165
+ } ${item.value ? `value ${item.value.toString()}` : ""}`;
166
+ });
167
+ return asString;
168
+ } else if (error.response.data.error) {
169
+ return error.response.data.error.toString();
170
+ } else if (error.response.statusText) {
171
+ return error.response.statusText.toString();
172
+ } else {
173
+ return error.response.data.toString();
174
+ }
175
+ } else {
176
+ return error.message ? error.message : JSON.stringify(error.toString());
177
+ }
178
+ }
179
+ },
180
+
138
181
  /**
139
- * Did not receive a timely response from upstream server while acting as a gateway or proxy.
182
+ * Returns the code of the error as a number
183
+ * @param {Object} error
184
+ * @returns {Number} The error code
140
185
  */
141
- GATEWAY_TIMEOUT: 504,
186
+ getErrorType: (error) => {
187
+ if (error?.response?.status) {
188
+ return error.response.status;
189
+ } else return responseType.SERVICE_UNAVAILABLE;
190
+ },
191
+
142
192
  /**
143
- * The HTTP protocol version used in the request message is not supported.
193
+ * Return the error information to include just the status and the message
194
+ * @param {*} error
195
+ * @returns Object
144
196
  */
145
- HTTP_VERSION_NOT_SUPPORTED: 505,
197
+ getErrorInformation: (error) => {
198
+ return {
199
+ status: getErrorType(error),
200
+ message: errorToString(error),
201
+ };
202
+ },
203
+
146
204
  /**
147
- * A failure occurred during initialization of services. API will be unavailable.
205
+ * Returns true if an exception should be handled to the business and presentation layer
206
+ * @param {*} returnAllExceptions - If set true all exceptions will be passed
207
+ * @param {*} error - The error returned by the server
148
208
  */
149
- INITIALIZATION_FAILURE: 550,
150
- };
151
-
152
- /**
153
- * Returns the error as a string
154
- * @param {Object} error
155
- */
156
- export const errorToString = (error) => {
157
- if (error != null) {
158
- if (error?.response?.data) {
159
- let asString = "";
160
- if (Array.isArray(error.response.data.errors)) {
161
- error.response.data.errors.forEach((item, index) => {
162
- asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
163
- item.param
164
- } ${item.value ? `value ${item.value.toString()}` : ""}`;
165
- });
166
- return asString;
167
- } else if (error.response.data.error) {
168
- return error.response.data.error.toString();
169
- } else if (error.response.statusText) {
170
- return error.response.statusText.toString();
171
- } else {
172
- return error.response.data.toString();
173
- }
209
+ shouldReturnError: (returnAllExceptions, error) => {
210
+ if (getErrorType(error) === responseType.UNAUTHORIZED) {
211
+ return returnAllExceptions;
174
212
  } else {
175
- return error.message ? error.message : error.toString();
213
+ return true;
176
214
  }
177
- }
215
+ },
178
216
  };
179
-
180
- /**
181
- * Returns the code of the error as a number
182
- * @param {Object} error
183
- * @returns {Number} The error code
184
- */
185
- export const getErrorType = (error) => {
186
- if (error?.response?.status) {
187
- return error.response.status;
188
- } else return responseType.SERVICE_UNAVAILABLE;
189
- };
190
-
191
- /**
192
- * Return the error information to include just the status and the message
193
- * @param {*} error
194
- * @returns Object
195
- */
196
- export const getErrorInformation = (error) => {
197
- return {
198
- status: getErrorType(error),
199
- message: errorToString(error),
200
- };
201
- };
202
-
203
- /**
204
- * Returns true if an exception should be handled to the business and presentation layer
205
- * @param {*} returnAllExceptions - If set true all exceptions will be passed
206
- * @param {*} error - The error returned by the server
207
- */
208
- export const shouldReturnError = (returnAllExceptions, error) => {
209
- if (getErrorType(error) === responseType.UNAUTHORIZED) {
210
- return returnAllExceptions;
211
- } else {
212
- return true;
213
- }
214
- };
215
-
216
- export default instance;
package/lib/config.js CHANGED
@@ -1,16 +1,14 @@
1
- import axios from "./axios";
1
+ const axios = require("./axios");
2
2
 
3
- export default {
3
+ module.exports = {
4
4
  axios: axios,
5
5
 
6
6
  /**
7
7
  * Get the specified configuration by Id. It returns a promise
8
- *
9
8
  * @param {String} id - the id of the configuration element
10
9
  * @param {String} authToken - Authorization token
11
- *
12
10
  */
13
- getConfigurationById(id, authToken) {
11
+ getConfigurationById: (id, authToken) => {
14
12
  return new Promise(function (resolve, reject) {
15
13
  const getConfigInformationRequest = axios.get(
16
14
  `api/v1/configurations/configuration/id/${id}`,
@@ -28,12 +26,10 @@ export default {
28
26
 
29
27
  /**
30
28
  * Get the specified configuration by type. It returns a promise
31
- *
32
29
  * @param {String} type - the id of the configuration element
33
30
  * @param {String} authToken - Authorization token
34
- *
35
31
  */
36
- getConfigurationByType(type, authToken) {
32
+ getConfigurationByType: (type, authToken) => {
37
33
  return new Promise(function (resolve, reject) {
38
34
  const getConfigInformationRequest = axios.get(
39
35
  `api/v1/configurations/configuration/type/${type}`,
@@ -50,15 +46,12 @@ export default {
50
46
  },
51
47
 
52
48
  /**
53
- *
54
49
  * Set the specified configuration by Id. It returns a promise
55
- *
56
50
  * @param {String} id - the id of the configuration element
57
51
  * @param {Object} data - the object containing the updated configuration element
58
52
  * @param {String} authToken - Authorization token
59
- *
60
53
  */
61
- setConfigurationById(id, data, authToken) {
54
+ setConfigurationById: (id, data, authToken) => {
62
55
  return new Promise(function (resolve, reject) {
63
56
  const getConfigInformationRequest = axios.post(
64
57
  `api/v1/configurations/configuration/${id}`,