@stackfactor/client-api 1.0.31 → 1.0.33

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
@@ -18,7 +18,6 @@ const skillAssessment = require("./lib/skillAssessments");
18
18
  const skillAssessmentTestingSession = require("./lib/skillAssessmentTestingSession");
19
19
  const skillTemplate = require("./lib/skillTemplate");
20
20
  const team = require("./lib/teams");
21
- const templates = require("./lib/templates");
22
21
  const tenant = require("./lib/tenants");
23
22
  const trainingPlanTemplate = require("./lib/trainingPlanTemplate");
24
23
  const trainingPlan = require("./lib/trainingPlans");
@@ -51,7 +50,6 @@ module.exports = {
51
50
  skillAssessmentTestingSession,
52
51
  skillTemplate,
53
52
  team,
54
- templates,
55
53
  tenant,
56
54
  trainingPlanTemplate,
57
55
  trainingPlan,
@@ -1,240 +1,216 @@
1
- import { axios } from "./axiosClient";
1
+ import axios from "./axiosClient";
2
2
 
3
- module.exports = {
4
- axios: axios,
3
+ /**
4
+ * Get all permissions
5
+ * @param {String} authToken The authentication token
6
+ */
7
+ export const getAllUserNotifications = (authToken) => {
8
+ return new Promise(function (resolve, reject) {
9
+ const request = axios.get(`api/v1/actionnotifications`, {
10
+ headers: { authorization: authToken },
11
+ });
12
+ request
13
+ .then((response) => {
14
+ resolve(response.data);
15
+ })
16
+ .catch((error) => {
17
+ reject(error);
18
+ });
19
+ });
20
+ };
5
21
 
6
- /**
7
- * Get all permissions
8
- * @param {String} authToken The authentication token
9
- */
10
- getAllUserNotifications: (authToken) => {
11
- return new Promise(function (resolve, reject) {
12
- const request = axios.get(`api/v1/actionnotifications`, {
13
- headers: { authorization: authToken },
22
+ /**
23
+ * Mark notifications as open or viewed
24
+ * @param {Array<String>} ids The id of the notifications to be marked
25
+ * @param {String} status The new status
26
+ * @param {String} authToken The authentication token
27
+ */
28
+ export const markNotifications = (ids, status, authToken) => {
29
+ return new Promise(function (resolve, reject) {
30
+ const request = axios.put(
31
+ `api/v1/actionnotifications/mark`,
32
+ {
33
+ ids: ids,
34
+ status: status,
35
+ },
36
+ { headers: { authorization: authToken } }
37
+ );
38
+ request
39
+ .then((response) => {
40
+ resolve(response.data);
41
+ })
42
+ .catch((error) => {
43
+ reject(error);
14
44
  });
15
- request
16
- .then((response) => {
17
- resolve(response.data);
18
- })
19
- .catch((error) => {
20
- reject(error);
21
- });
22
- });
23
- },
45
+ });
46
+ };
24
47
 
25
- /**
26
- * Mark notifications as open or viewed
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
30
- */
31
- markNotifications: (ids, status, authToken) => {
32
- return new Promise(function (resolve, reject) {
33
- const request = axios.put(
34
- `api/v1/actionnotifications/mark`,
35
- {
36
- ids: ids,
37
- status: status,
38
- },
39
- { headers: { authorization: authToken } }
40
- );
41
- request
42
- .then((response) => {
43
- resolve(response.data);
44
- })
45
- .catch((error) => {
46
- reject(error);
47
- });
48
- });
49
- },
48
+ /**
49
+ * Process a notification
50
+ * @param {String} id The notification id
51
+ * @param {String} action The action to be executed
52
+ * @param {String} comment The comment to be saved in the notification
53
+ * @param {String} authToken The authentication token
54
+ */
55
+ export const processNotification = (id, action, comment, authToken) => {
56
+ return new Promise(function (resolve, reject) {
57
+ const request = axios.put(
58
+ `api/v1/actionnotifications/process`,
59
+ {
60
+ id: id,
61
+ action: action,
62
+ comment: comment,
63
+ },
64
+ { headers: { authorization: authToken } }
65
+ );
66
+ request
67
+ .then((response) => {
68
+ resolve(response.data);
69
+ })
70
+ .catch((error) => {
71
+ reject(error);
72
+ });
73
+ });
74
+ };
50
75
 
51
- /**
52
- * Process a notification
53
- * @param {String} id The notification id
54
- * @param {String} action The action to be executed
55
- * @param {String} comment The comment to be saved in the notification
56
- * @param {String} authToken The authentication token
57
- */
58
- processNotification: (id, action, comment, authToken) => {
59
- return new Promise(function (resolve, reject) {
60
- const request = axios.put(
61
- `api/v1/actionnotifications/process`,
62
- {
63
- id: id,
64
- action: action,
65
- comment: comment,
66
- },
67
- { headers: { authorization: authToken } }
68
- );
69
- request
70
- .then((response) => {
71
- resolve(response.data);
72
- })
73
- .catch((error) => {
74
- reject(error);
75
- });
76
+ /**
77
+ * Get groups for current tenant
78
+ * @param {String} authToken The authentication token
79
+ */
80
+ export const getGroups = (authToken) => {
81
+ return new Promise(function (resolve, reject) {
82
+ const request = axios.get(`api/v1/groups/`, {
83
+ headers: { authorization: authToken },
76
84
  });
77
- },
78
-
79
- /**
80
- * Get groups for current tenant
81
- * @param {String} authToken The authentication token
82
- */
83
- getGroups: (authToken) => {
84
- return new Promise(function (resolve, reject) {
85
- const request = axios.get(`api/v1/groups/`, {
86
- headers: { authorization: authToken },
85
+ request
86
+ .then((response) => {
87
+ resolve(response.data);
88
+ })
89
+ .catch((error) => {
90
+ reject(error);
87
91
  });
88
- request
89
- .then((response) => {
90
- resolve(response.data);
91
- })
92
- .catch((error) => {
93
- reject(error);
94
- });
95
- });
96
- },
92
+ });
93
+ };
97
94
 
98
- /**
99
- * Get current user permissions
100
- * @param {String} authToken The authentication token
101
- */
102
- getUserPermissions: (authToken) => {
103
- return new Promise(function (resolve, reject) {
104
- const request = axios.get(`api/v1/groups/users/getuserpermissions`, {
105
- headers: { authorization: authToken },
106
- });
107
- request
108
- .then((response) => {
109
- resolve(response.data);
110
- })
111
- .catch((error) => {
112
- reject(error);
113
- });
95
+ /**
96
+ * Get current user permissions
97
+ * @param {String} authToken The authentication token
98
+ */
99
+ export const getUserPermissions = (authToken) => {
100
+ return new Promise(function (resolve, reject) {
101
+ const request = axios.get(`api/v1/groups/users/getuserpermissions`, {
102
+ headers: { authorization: authToken },
114
103
  });
115
- },
104
+ request
105
+ .then((response) => {
106
+ resolve(response.data);
107
+ })
108
+ .catch((error) => {
109
+ reject(error);
110
+ });
111
+ });
112
+ };
116
113
 
117
- /**
118
- * Build in permissions
119
- */
120
- permissions: {
121
- ADMIN_PROMOTE_CONTENT: "5ea3d10bea252025c8ec351b",
122
- ADMIN_AUTHOR_CONTENT: "5ea3d1152839450e16e72bba",
123
- AUTHOR_CONTENT: "5fac210560e43de7c6b4a208",
124
- MANAGE_BILLING: "5e1570cd03f676213bfdcd08",
125
- MANAGE_CONTENT_PROVIDERS: "5f0fa12f16a720fde58ea820",
126
- MANAGE_GROUPS: "5dd612fe59e518ac87b8cf8e",
127
- MANAGE_OWN_PROFILE_INFORMATION_AUTO_APP: "5fac210e7e6539d37a897c94",
128
- MANAGE_ORGANIZATION_INFORMATION: "5dd612d5338ea9a6ae6326da",
129
- MANAGE_OWN_SKILL_SET_AUTO_APPROVE: "5fac21164351c6727a34cd4e",
130
- MANAGE_SETTINGS: "5e1570e087d836dc77888a5f",
131
- MANAGE_TEAM_INFORMATION_AUTO_APPROVE: "5fac211e6c8f874bd7137b98",
132
- MANAGE_TEAMS: "5dd61314afc2455a89b1a37b",
133
- MANAGE_USERS: "5dd612e40f0bc559c41a2b29",
134
- PROMOTE_CONTENT: "5fac2126427ce31f8a92c0cb",
135
- MANAGE_PLAN_TEMPLATES: "5dd61305a73c68b44c3f0827",
136
- },
137
- /**
138
- * Remove permissions from group
139
- * @param {String} groupId The group Id
140
- * @param {Array<String>} permissions The permissions to be removed from the group
141
- * @param {String} authToken The authentication token
142
- */
143
- removePermissionsFromGroup: (groupId, permissions, authToken) => {
144
- return new Promise(function (resolve, reject) {
145
- const request = axios.post(
146
- `api/v1/groups/permissions/remove/`,
147
- {
148
- groupId: groupId,
149
- permissions: permissions,
150
- },
151
- { headers: { authorization: authToken } }
152
- );
153
- request
154
- .then((response) => {
155
- resolve(response.data);
156
- })
157
- .catch((error) => {
158
- reject(error);
159
- });
160
- });
161
- },
114
+ /**
115
+ * Remove permissions from group
116
+ * @param {String} groupId The group Id
117
+ * @param {Array<String>} permissions The permissions to be removed from the group
118
+ * @param {String} authToken The authentication token
119
+ */
120
+ export const removePermissionsFromGroup = (groupId, permissions, authToken) => {
121
+ return new Promise(function (resolve, reject) {
122
+ const request = axios.post(
123
+ `api/v1/groups/permissions/remove/`,
124
+ {
125
+ groupId: groupId,
126
+ permissions: permissions,
127
+ },
128
+ { headers: { authorization: authToken } }
129
+ );
130
+ request
131
+ .then((response) => {
132
+ resolve(response.data);
133
+ })
134
+ .catch((error) => {
135
+ reject(error);
136
+ });
137
+ });
138
+ };
162
139
 
163
- /**
164
- * Remove users from group
165
- * @param {String} groupId The group Id
166
- * @param {Array<String>} users The users to be removed from the group
167
- * @param {String} authToken The authentication token
168
- */
169
- removeUsersFromGroup: (groupId, users, authToken) => {
170
- return new Promise(function (resolve, reject) {
171
- const request = axios.post(
172
- `api/v1/groups/users/remove/`,
173
- {
174
- groupId: groupId,
175
- users: users,
176
- },
177
- { headers: { authorization: authToken } }
178
- );
179
- request
180
- .then((response) => {
181
- resolve(response.data);
182
- })
183
- .catch((error) => {
184
- reject(error);
185
- });
186
- });
187
- },
140
+ /**
141
+ * Remove users from group
142
+ * @param {String} groupId The group Id
143
+ * @param {Array<String>} users The users to be removed from the group
144
+ * @param {String} authToken The authentication token
145
+ */
146
+ export const removeUsersFromGroup = (groupId, users, authToken) => {
147
+ return new Promise(function (resolve, reject) {
148
+ const request = axios.post(
149
+ `api/v1/groups/users/remove/`,
150
+ {
151
+ groupId: groupId,
152
+ users: users,
153
+ },
154
+ { headers: { authorization: authToken } }
155
+ );
156
+ request
157
+ .then((response) => {
158
+ resolve(response.data);
159
+ })
160
+ .catch((error) => {
161
+ reject(error);
162
+ });
163
+ });
164
+ };
188
165
 
189
- /*
190
- * Set group as defualt
191
- * @param {String} groupId The group Id
192
- * @param {String} authToken The authentication token
193
- */
194
- setDefault: (groupId, authToken) => {
195
- return new Promise(function (resolve, reject) {
196
- const request = axios.put(
197
- `api/v1/groups/setDefault/`,
198
- {
199
- id: groupId,
200
- },
201
- { headers: { authorization: authToken } }
202
- );
203
- request
204
- .then((response) => {
205
- resolve(response.data);
206
- })
207
- .catch((error) => {
208
- reject(error);
209
- });
210
- });
211
- },
166
+ /*
167
+ * Set group as defualt
168
+ * @param {String} groupId The group Id
169
+ * @param {String} authToken The authentication token
170
+ */
171
+ export const setDefault = (groupId, authToken) => {
172
+ return new Promise(function (resolve, reject) {
173
+ const request = axios.put(
174
+ `api/v1/groups/setDefault/`,
175
+ {
176
+ id: groupId,
177
+ },
178
+ { headers: { authorization: authToken } }
179
+ );
180
+ request
181
+ .then((response) => {
182
+ resolve(response.data);
183
+ })
184
+ .catch((error) => {
185
+ reject(error);
186
+ });
187
+ });
188
+ };
212
189
 
213
- /**
214
- * Update group
215
- * @param {String} groupId The group Id
216
- * @param {string} name The updated name of the group
217
- * @param {string} description The updated description of the group
218
- * @param {String} authToken The authentication token
219
- */
220
- updateGroup: (groupId, name, description, authToken) => {
221
- return new Promise(function (resolve, reject) {
222
- const request = axios.patch(
223
- `api/v1/groups/group/`,
224
- {
225
- id: groupId,
226
- name: name,
227
- description: description,
228
- },
229
- { headers: { authorization: authToken } }
230
- );
231
- request
232
- .then((response) => {
233
- resolve(response.data);
234
- })
235
- .catch((error) => {
236
- reject(error);
237
- });
238
- });
239
- },
190
+ /**
191
+ * Update group
192
+ * @param {String} groupId The group Id
193
+ * @param {string} name The updated name of the group
194
+ * @param {string} description The updated description of the group
195
+ * @param {String} authToken The authentication token
196
+ */
197
+ export const updateGroup = (groupId, name, description, authToken) => {
198
+ return new Promise(function (resolve, reject) {
199
+ const request = axios.patch(
200
+ `api/v1/groups/group/`,
201
+ {
202
+ id: groupId,
203
+ name: name,
204
+ description: description,
205
+ },
206
+ { headers: { authorization: authToken } }
207
+ );
208
+ request
209
+ .then((response) => {
210
+ resolve(response.data);
211
+ })
212
+ .catch((error) => {
213
+ reject(error);
214
+ });
215
+ });
240
216
  };
package/lib/address.js CHANGED
@@ -1,29 +1,23 @@
1
- import { axios } from "./axiosClient";
1
+ import axios from "./axiosClient";
2
2
 
3
- module.exports = {
4
- axios: axios,
5
-
6
- /**
7
- * Validate Address
8
- *
9
- * @param {String} input - the address in raw format
10
- * @param {String} authToken - Authorization token
11
- *
12
- */
13
- autoComplete: (input, authToken) => {
14
- return new Promise(function (resolve, reject) {
15
- const getAddressesRequest = axios.post(
16
- `api/v1/address/autocomplete/`,
17
- { input: input },
18
- { headers: { authorization: authToken } }
19
- );
20
- getAddressesRequest
21
- .then((response) => {
22
- resolve(response.data);
23
- })
24
- .catch((error) => {
25
- reject(error);
26
- });
27
- });
28
- },
3
+ /**
4
+ * Validate Address
5
+ * @param {String} input - the address in raw format
6
+ * @param {String} authToken - Authorization token
7
+ */
8
+ export const autoComplete = (input, authToken) => {
9
+ return new Promise(function (resolve, reject) {
10
+ const getAddressesRequest = axios.post(
11
+ `api/v1/address/autocomplete/`,
12
+ { input: input },
13
+ { headers: { authorization: authToken } }
14
+ );
15
+ getAddressesRequest
16
+ .then((response) => {
17
+ resolve(response.data);
18
+ })
19
+ .catch((error) => {
20
+ reject(error);
21
+ });
22
+ });
29
23
  };
@@ -1,10 +1,10 @@
1
- const axios = require("axios");
2
- const https = require("https");
3
- const utils = require("./utils");
1
+ import client from "axios";
2
+ import https from "https";
3
+ import utils from "./utils";
4
4
 
5
5
  const baseUrl = utils.getBaseUrl();
6
6
 
7
- let instance = axios.create({
7
+ export default client.create({
8
8
  baseURL: baseUrl,
9
9
  httpsAgent: new https.Agent({
10
10
  rejectUnauthorized: false,
@@ -12,71 +12,65 @@ let instance = axios.create({
12
12
  });
13
13
 
14
14
  /**
15
- * Server response type
15
+ * Returns the error as a string
16
+ * @param {Object} error
16
17
  */
17
- module.exports = {
18
- axios: instance,
19
- /**
20
- * Returns the error as a string
21
- * @param {Object} error
22
- */
23
- errorToString: (error) => {
24
- if (error != null) {
25
- if (error?.response?.data) {
26
- let asString = "";
27
- if (Array.isArray(error.response.data.errors)) {
28
- error.response.data.errors.forEach((item, index) => {
29
- asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
30
- item.param
31
- } ${item.value ? `value ${item.value.toString()}` : ""}`;
32
- });
33
- return asString;
34
- } else if (error.response.data.error) {
35
- return error.response.data.error.toString();
36
- } else if (error.response.statusText) {
37
- return error.response.statusText.toString();
38
- } else {
39
- return error.response.data.toString();
40
- }
18
+ export const errorToString = (error) => {
19
+ if (error != null) {
20
+ if (error?.response?.data) {
21
+ let asString = "";
22
+ if (Array.isArray(error.response.data.errors)) {
23
+ error.response.data.errors.forEach((item, index) => {
24
+ asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
25
+ item.param
26
+ } ${item.value ? `value ${item.value.toString()}` : ""}`;
27
+ });
28
+ return asString;
29
+ } else if (error.response.data.error) {
30
+ return error.response.data.error.toString();
31
+ } else if (error.response.statusText) {
32
+ return error.response.statusText.toString();
41
33
  } else {
42
- return error.message ? error.message : "Unknown error";
34
+ return error.response.data.toString();
43
35
  }
36
+ } else {
37
+ return error.message ? error.message : "Unknown error";
44
38
  }
45
- },
39
+ }
40
+ };
46
41
 
47
- /**
48
- * Returns the code of the error as a number
49
- * @param {Object} error
50
- * @returns {Number} The error code
51
- */
52
- getErrorType: (error) => {
53
- if (error?.response?.status) {
54
- return error.response.status;
55
- } else return responseType.SERVICE_UNAVAILABLE;
56
- },
42
+ /**
43
+ * Returns the code of the error as a number
44
+ * @param {Object} error
45
+ * @returns {Number} The error code
46
+ */
47
+ export const getErrorType = (error) => {
48
+ if (error?.response?.status) {
49
+ return error.response.status;
50
+ } else return responseType.SERVICE_UNAVAILABLE;
51
+ };
57
52
 
58
- /**
59
- * Return the error information to include just the status and the message
60
- * @param {Object} error
61
- * @returns Object
62
- */
63
- getErrorInformation: (error) => {
64
- return {
65
- status: getErrorType(error),
66
- message: errorToString(error),
67
- };
68
- },
53
+ /**
54
+ * Return the error information to include just the status and the message
55
+ * @param {Object} error
56
+ * @returns Object
57
+ */
58
+ export const getErrorInformation = (error) => {
59
+ return {
60
+ status: getErrorType(error),
61
+ message: errorToString(error),
62
+ };
63
+ };
69
64
 
70
- /**
71
- * Returns true if an exception should be handled to the business and presentation layer
72
- * @param {Boolean} returnAllExceptions - If set true all exceptions will be passed
73
- * @param {Object} error - The error returned by the server
74
- */
75
- shouldReturnError: (returnAllExceptions, error) => {
76
- if (getErrorType(error) === responseType.UNAUTHORIZED) {
77
- return returnAllExceptions;
78
- } else {
79
- return true;
80
- }
81
- },
65
+ /**
66
+ * Returns true if an exception should be handled to the business and presentation layer
67
+ * @param {Boolean} returnAllExceptions - If set true all exceptions will be passed
68
+ * @param {Object} error - The error returned by the server
69
+ */
70
+ export const shouldReturnError = (returnAllExceptions, error) => {
71
+ if (getErrorType(error) === responseType.UNAUTHORIZED) {
72
+ return returnAllExceptions;
73
+ } else {
74
+ return true;
75
+ }
82
76
  };