@stackfactor/client-api 1.0.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.
@@ -0,0 +1,94 @@
1
+ import axios from "./axios";
2
+
3
+ export default {
4
+ axios: axios,
5
+
6
+ /**
7
+ * Get the integration configuration
8
+ * @param {[String]} ids
9
+ * @param {Number} type
10
+ * @param {String} token Authorization token
11
+ */
12
+ getIntegrationsConfiguration(ids, type, token) {
13
+ return new Promise(function (resolve, reject) {
14
+ let requestData = { type: type };
15
+ if (ids) requestData.ids = ids;
16
+ let confirmationRequest = axios.post(
17
+ "api/v1/integrationsconfiguration",
18
+ requestData,
19
+ {
20
+ headers: { authorization: token },
21
+ }
22
+ );
23
+ confirmationRequest
24
+ .then((response) => {
25
+ resolve(response.data);
26
+ })
27
+ .catch((error) => {
28
+ reject(error);
29
+ });
30
+ });
31
+ },
32
+
33
+ /**
34
+ * Save integration configuration
35
+ * @param {String} id The id of the integration configurationto be updated
36
+ * @param {Number} type The type of configuration
37
+ * @param {Object} configuration Data used to update the integration configuration
38
+ * @param {String} token Authorization token
39
+ */
40
+ saveIntegrationConfiguration(id, type, configuration, token) {
41
+ return new Promise(function (resolve, reject) {
42
+ const requestData = {
43
+ id: id,
44
+ configuration: configuration,
45
+ type: type,
46
+ };
47
+ let confirmationRequest = axios.put(
48
+ `api/v1/integrationsconfiguration`,
49
+ requestData,
50
+ {
51
+ headers: { authorization: token },
52
+ }
53
+ );
54
+ confirmationRequest
55
+ .then((response) => {
56
+ resolve(response.data);
57
+ })
58
+ .catch((error) => {
59
+ reject(error);
60
+ });
61
+ });
62
+ },
63
+
64
+ /**
65
+ * Test integration configuration
66
+ * @param {String} id The id of the integration to be updated
67
+ * @param {String} type The type of configuration
68
+ * @param {Object} configuration Configuration to be tested
69
+ * @param {String} token Authorization token
70
+ */
71
+ testIntegrationConfiguration(id, type, configuration, token) {
72
+ return new Promise(function (resolve, reject) {
73
+ const requestData = {
74
+ id: id,
75
+ configuration: configuration,
76
+ type: type,
77
+ };
78
+ let confirmationRequest = axios.post(
79
+ `api/v1/integrationsconfiguration/testConfiguration`,
80
+ requestData,
81
+ {
82
+ headers: { authorization: token },
83
+ }
84
+ );
85
+ confirmationRequest
86
+ .then((response) => {
87
+ resolve(response.data);
88
+ })
89
+ .catch((error) => {
90
+ reject(error);
91
+ });
92
+ });
93
+ },
94
+ };
@@ -0,0 +1,79 @@
1
+ /* eslint-disable no-undef */
2
+ import axios from "../axios";
3
+
4
+ export default {
5
+ axios: axios,
6
+ /**
7
+ * Generate content
8
+ * @param {Array<String>} data
9
+ * @param {String} contentType
10
+ * @param {String} integrationId
11
+ * @param {String} token
12
+ * @returns {Object}
13
+ */
14
+ generateContent(data, contentType, integrationId, token) {
15
+ return new Promise(function (resolve, reject) {
16
+ let data_ = {
17
+ data: data,
18
+ contentType: contentType,
19
+ };
20
+ if (integrationId) data.integrationId = integrationId;
21
+ const request = axios.post(`api/v1/contentgenerators/generate`, data_, {
22
+ headers: { authorization: token },
23
+ });
24
+ request
25
+ .then((response) => {
26
+ resolve(response.data);
27
+ })
28
+ .catch((error) => {
29
+ reject(error);
30
+ });
31
+ });
32
+ },
33
+
34
+ /**
35
+ * Generate content aync
36
+ * @param {String} id
37
+ * @param {Object} data
38
+ * @param {String} contentType
39
+ * @param {String} elementType
40
+ * @param {String} integrationId
41
+ * @param {String} comments
42
+ * @param {String} token
43
+ * @returns {Object}
44
+ */
45
+ generateContentAsync(
46
+ id,
47
+ data,
48
+ contentType,
49
+ elementType,
50
+ integrationId,
51
+ comments,
52
+ token
53
+ ) {
54
+ return new Promise(function (resolve, reject) {
55
+ let data_ = {
56
+ data: data,
57
+ comments: comments,
58
+ contentType: contentType,
59
+ elementType: elementType,
60
+ id: id,
61
+ };
62
+ if (integrationId) data_.integrationId = integrationId;
63
+ const request = axios.post(
64
+ `api/v1/contentgenerators/generateasync`,
65
+ data_,
66
+ {
67
+ headers: { authorization: token },
68
+ }
69
+ );
70
+ request
71
+ .then((response) => {
72
+ resolve(response.data);
73
+ })
74
+ .catch((error) => {
75
+ reject(error);
76
+ });
77
+ });
78
+ },
79
+ };
package/lib/logger.js ADDED
@@ -0,0 +1,61 @@
1
+ import axios from "./axios";
2
+
3
+ export default {
4
+ axios: axios,
5
+
6
+ /**
7
+ * Create a comment for a specified element id
8
+ * @param {String} elementId
9
+ * @param {String} elementType
10
+ * @param {Object} data
11
+ * @param {String} token Authorization token
12
+ */
13
+ comment(elementId, elementType, data, token) {
14
+ return new Promise(function (resolve, reject) {
15
+ let confirmationRequest = axios.post(
16
+ "api/v1/logger/comment/",
17
+ {
18
+ data: data,
19
+ elementId: elementId,
20
+ elementType: elementType,
21
+ },
22
+ {
23
+ headers: { authorization: token },
24
+ }
25
+ );
26
+ confirmationRequest
27
+ .then((response) => {
28
+ resolve(response.data);
29
+ })
30
+ .catch((error) => {
31
+ reject(error);
32
+ });
33
+ });
34
+ },
35
+
36
+ /**
37
+ * Get the list of logger entries for selected element
38
+ * @param {String} elementId
39
+ * @param {number} page The results page
40
+ * @param {number} elementsPerPage The number of elements per page
41
+ * @param {String} token
42
+ * @returns
43
+ */
44
+ getListByElementId(elementId, page, elementsPerPage, token) {
45
+ return new Promise(function (resolve, reject) {
46
+ let data = {};
47
+ if (elementsPerPage !== null) data.elementsPerPage = elementsPerPage;
48
+ if (page !== null) data.page = page;
49
+ const getTokensRequest = axios.post(`api/v1/logger/${elementId}`, data, {
50
+ headers: { authorization: token },
51
+ });
52
+ getTokensRequest
53
+ .then((result) => {
54
+ resolve(result.data);
55
+ })
56
+ .catch((error) => {
57
+ reject(error);
58
+ });
59
+ });
60
+ },
61
+ };
package/lib/role.js ADDED
@@ -0,0 +1,266 @@
1
+ import axios from "./axios";
2
+
3
+ // eslint-disable-next-line no-undef
4
+ export default {
5
+ axios: axios,
6
+
7
+ /**
8
+ * Create role and set information
9
+ * @param {Object} data
10
+ * @param {String} token Authorization token
11
+ */
12
+ createRole(data, token) {
13
+ return new Promise(function (resolve, reject) {
14
+ let confirmationRequest = axios.put(
15
+ "api/v1/roles",
16
+ { data: data },
17
+ {
18
+ headers: { authorization: token },
19
+ }
20
+ );
21
+ confirmationRequest
22
+ .then((response) => {
23
+ resolve(response.data);
24
+ })
25
+ .catch((error) => {
26
+ reject(error);
27
+ });
28
+ });
29
+ },
30
+
31
+ /**
32
+ * Create from from template
33
+ * @param {String} templateId
34
+ * @param {Object} data
35
+ * @param {String} token Authorization token
36
+ */
37
+ createRoleFromTemplate(templateId, data, token) {
38
+ return new Promise(function (resolve, reject) {
39
+ const requestData = {
40
+ templateId: templateId,
41
+ data: data,
42
+ };
43
+ let confirmationRequest = axios.put(
44
+ "api/v1/roles/createfromtemplate/",
45
+ requestData,
46
+ {
47
+ headers: { authorization: token },
48
+ }
49
+ );
50
+ confirmationRequest
51
+ .then((response) => {
52
+ resolve(response.data);
53
+ })
54
+ .catch((error) => {
55
+ reject(error);
56
+ });
57
+ });
58
+ },
59
+
60
+ /**
61
+ * Delete role
62
+ * @param {String} id The id of the role to be deleted
63
+ * @param {String} comment The comment included with the deletion
64
+ * @param {String} token Authorization token
65
+ */
66
+ deleteRole(id, comment, token) {
67
+ return new Promise(function (resolve, reject) {
68
+ const data = {
69
+ id: id,
70
+ };
71
+ if (comment) data.comment = comment;
72
+ const request = axios.delete(`api/v1/roles/`, {
73
+ headers: { authorization: token },
74
+ data: data,
75
+ });
76
+ request
77
+ .then((response) => {
78
+ resolve(response.data);
79
+ })
80
+ .catch((error) => {
81
+ reject(error);
82
+ });
83
+ });
84
+ },
85
+
86
+ /**
87
+ * Discard the role draft changes
88
+ * @param {String} id The id of the role to be deleted
89
+ * @param {String} token Authorization token
90
+ */
91
+ discardRoleChanges(id, token) {
92
+ return new Promise(function (resolve, reject) {
93
+ const data = {};
94
+ const request = axios.get(`api/v1/roles/discard/${id}`, {
95
+ headers: { authorization: token },
96
+ data: data,
97
+ });
98
+ request
99
+ .then((response) => {
100
+ resolve(response.data);
101
+ })
102
+ .catch((error) => {
103
+ reject(error);
104
+ });
105
+ });
106
+ },
107
+
108
+ /**
109
+ * Get role information
110
+ * @param {number} id The id of the role
111
+ * @param {String} token Authorization token
112
+ */
113
+ getRoleInformationById(id, version, token) {
114
+ return new Promise(function (resolve, reject) {
115
+ let confirmationRequest = axios.get(
116
+ `api/v1/roles/role/${id}/${version}`,
117
+ {
118
+ headers: { authorization: token },
119
+ }
120
+ );
121
+ confirmationRequest
122
+ .then((response) => {
123
+ resolve(response.data);
124
+ })
125
+ .catch((error) => {
126
+ reject(error);
127
+ });
128
+ });
129
+ },
130
+
131
+ /**
132
+ * Get roles list
133
+ * @param {Object} filter The filter used to select the roles
134
+ * @param {String} version The version to be retrieved
135
+ * @param {Boolean} includeDeleted If true it will return deleted records as well
136
+ * @param {boolean} includeDetailedInformation If true it will return detailed information
137
+ * @param {Boolean} returnDefaultIfVersionNotAvailable Return the default version if published not available
138
+ * @param {String} token Authorization token
139
+ */
140
+ getRolesList(
141
+ filter,
142
+ version,
143
+ includeDeleted,
144
+ includeDetailedInformation,
145
+ returnDefaultIfVersionNotAvailable,
146
+ token
147
+ ) {
148
+ return new Promise(function (resolve, reject) {
149
+ const requestData = {
150
+ version: version,
151
+ includeDeleted: includeDeleted,
152
+ includeDetailedInformation: includeDetailedInformation,
153
+ returnDefaultIfVersionNotAvailable: returnDefaultIfVersionNotAvailable,
154
+ };
155
+ if (filter) requestData.filter = filter;
156
+ let confirmationRequest = axios.post(`api/v1/roles`, requestData, {
157
+ headers: { authorization: token },
158
+ });
159
+ confirmationRequest
160
+ .then((response) => {
161
+ resolve(response.data);
162
+ })
163
+ .catch((error) => {
164
+ reject(error);
165
+ });
166
+ });
167
+ },
168
+
169
+ /**
170
+ * Publish role
171
+ * @param {number} id The id of the role to be published
172
+ * @param {String} comment The comment to be include with the request
173
+ * @param {String} token Authorization token
174
+ */
175
+ publishRole(id, comment, token) {
176
+ return new Promise(function (resolve, reject) {
177
+ let data = {};
178
+ if (comment) data.comment = comment;
179
+ let confirmationRequest = axios.post(`api/v1/roles/publish/${id}`, data, {
180
+ headers: { authorization: token },
181
+ });
182
+ confirmationRequest
183
+ .then((response) => {
184
+ resolve(response.data);
185
+ })
186
+ .catch((error) => {
187
+ reject(error);
188
+ });
189
+ });
190
+ },
191
+
192
+ /**
193
+ * Set role profile information
194
+ * @param {String} id The id of the role to be updated
195
+ * @param {Object} data Data used to update the role
196
+ * @param {String} token Authorization token
197
+ */
198
+ setRoleInformation(id, data, token) {
199
+ return new Promise(function (resolve, reject) {
200
+ const requestData = {
201
+ data: data,
202
+ id: id,
203
+ };
204
+ let confirmationRequest = axios.post(`api/v1/roles/update`, requestData, {
205
+ headers: { authorization: token },
206
+ });
207
+ confirmationRequest
208
+ .then((response) => {
209
+ resolve(response.data);
210
+ })
211
+ .catch((error) => {
212
+ reject(error);
213
+ });
214
+ });
215
+ },
216
+
217
+ /**
218
+ * Set user roles
219
+ * @param {String} id
220
+ * @param {Array<Object>} roles
221
+ * @param {String} token
222
+ */
223
+ setUserRoles(id, roles, roleDescription, token) {
224
+ return new Promise(function (resolve, reject) {
225
+ const requestData = {
226
+ roles: roles,
227
+ roleDescription: roleDescription,
228
+ };
229
+ if (id) requestData.userid = id;
230
+ let request = axios.post(`api/v1/roles/settouser/`, requestData, {
231
+ headers: { authorization: token },
232
+ });
233
+ request
234
+ .then((response) => {
235
+ resolve(response.data);
236
+ })
237
+ .catch((error) => {
238
+ reject(error);
239
+ });
240
+ });
241
+ },
242
+ /**
243
+ * Watch role
244
+ * @param {String} id The id of the skill to be updated
245
+ * @param {Boolean} watch Set to true or false
246
+ * @param {String} token Authorization token
247
+ */
248
+ watchRole(id, watch, token) {
249
+ return new Promise(function (resolve, reject) {
250
+ const requestData = {
251
+ id: id,
252
+ watch: watch,
253
+ };
254
+ let confirmationRequest = axios.post(`api/v1/roles/watch`, requestData, {
255
+ headers: { authorization: token },
256
+ });
257
+ confirmationRequest
258
+ .then((response) => {
259
+ resolve(response.data);
260
+ })
261
+ .catch((error) => {
262
+ reject(error);
263
+ });
264
+ });
265
+ },
266
+ };