@stackfactor/client-api 1.0.32 → 1.0.34

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.
@@ -1,341 +1,336 @@
1
- import { axios } from "./axiosClient";
2
- const errorToString = axios.errorToString;
1
+ import axios, { errorToString } from "./axiosClient";
3
2
  const axiosLib = require("axios");
4
3
  const htmlParser = require("node-html-parser");
5
4
  const htmlToText = require("html2plaintext");
6
5
 
7
- module.exports = {
8
- axios: axios,
9
-
10
- /**
11
- * Create integration and set information
12
- * @param {Object} data The new integration information
13
- * @param {String} token Authorization token
14
- */
15
- createIntegration: (data, token) => {
16
- return new Promise(function (resolve, reject) {
17
- const requestData = {
18
- data: data,
19
- };
20
- let confirmationRequest = axios.put("api/v1/integrations/", requestData, {
21
- headers: { authorization: token },
22
- });
23
- confirmationRequest
24
- .then((response) => {
25
- resolve(response.data);
26
- })
27
- .catch((error) => {
28
- reject(error);
29
- });
6
+ /**
7
+ * Create integration and set information
8
+ * @param {Object} data The new integration information
9
+ * @param {String} token Authorization token
10
+ */
11
+ export const createIntegration = (data, token) => {
12
+ return new Promise(function (resolve, reject) {
13
+ const requestData = {
14
+ data: data,
15
+ };
16
+ let confirmationRequest = axios.put("api/v1/integrations/", requestData, {
17
+ headers: { authorization: token },
30
18
  });
31
- },
19
+ confirmationRequest
20
+ .then((response) => {
21
+ resolve(response.data);
22
+ })
23
+ .catch((error) => {
24
+ reject(error);
25
+ });
26
+ });
27
+ };
32
28
 
33
- /**
34
- * Delete integration
35
- * @param {String} id The id of the integration to be deleted
36
- * @param {String} token Authorization token
37
- */
38
- deleteIntegration: (id, token) => {
39
- return new Promise(function (resolve, reject) {
40
- const request = axios.delete(`api/v1/integrations/`, {
41
- headers: { authorization: token },
42
- data: {
43
- id: id,
44
- },
29
+ /**
30
+ * Delete integration
31
+ * @param {String} id The id of the integration to be deleted
32
+ * @param {String} token Authorization token
33
+ */
34
+ export const deleteIntegration = (id, token) => {
35
+ return new Promise(function (resolve, reject) {
36
+ const request = axios.delete(`api/v1/integrations/`, {
37
+ headers: { authorization: token },
38
+ data: {
39
+ id: id,
40
+ },
41
+ });
42
+ request
43
+ .then((response) => {
44
+ resolve(response.data);
45
+ })
46
+ .catch((error) => {
47
+ reject(error);
45
48
  });
46
- request
47
- .then((response) => {
48
- resolve(response.data);
49
- })
50
- .catch((error) => {
51
- reject(error);
52
- });
49
+ });
50
+ };
51
+
52
+ /**
53
+ * Discard the integration draft changes
54
+ * @param {String} id The id of the role template to be deleted
55
+ * @param {String} token Authorization token
56
+ */
57
+ export const discardIntegrationChanges = (id, token) => {
58
+ return new Promise(function (resolve, reject) {
59
+ const data = {};
60
+ const request = axios.get(`api/v1/integrations/discard/${id}`, {
61
+ headers: { authorization: token },
62
+ data: data,
53
63
  });
54
- },
64
+ request
65
+ .then((response) => {
66
+ resolve(response.data);
67
+ })
68
+ .catch((error) => {
69
+ reject(error);
70
+ });
71
+ });
72
+ };
55
73
 
56
- /**
57
- * Discard the integration draft changes
58
- * @param {String} id The id of the role template to be deleted
59
- * @param {String} token Authorization token
60
- */
61
- discardIntegrationChanges: (id, token) => {
62
- return new Promise(function (resolve, reject) {
63
- const data = {};
64
- const request = axios.get(`api/v1/integrations/discard/${id}`, {
74
+ /**
75
+ * Get integration information
76
+ * @param {String} id The id of the integration
77
+ * @param {String} version The version of the integration to be received
78
+ * @param {String} token Authorization token
79
+ */
80
+ export const getIntegrationInformationById = (id, version, token) => {
81
+ return new Promise(function (resolve, reject) {
82
+ let confirmationRequest = axios.get(
83
+ `api/v1/integrations/${id}/${version}`,
84
+ {
65
85
  headers: { authorization: token },
66
- data: data,
86
+ }
87
+ );
88
+ confirmationRequest
89
+ .then((response) => {
90
+ resolve(response.data);
91
+ })
92
+ .catch((error) => {
93
+ reject(error);
67
94
  });
68
- request
69
- .then((response) => {
70
- resolve(response.data);
71
- })
72
- .catch((error) => {
73
- reject(error);
74
- });
75
- });
76
- },
95
+ });
96
+ };
77
97
 
78
- /**
79
- * Get integration information
80
- * @param {String} id The id of the integration
81
- * @param {String} version The version of the integration to be received
82
- * @param {String} token Authorization token
83
- */
84
- getIntegrationInformationById: (id, version, token) => {
85
- return new Promise(function (resolve, reject) {
86
- let confirmationRequest = axios.get(
87
- `api/v1/integrations/${id}/${version}`,
88
- {
89
- headers: { authorization: token },
90
- }
91
- );
92
- confirmationRequest
93
- .then((response) => {
94
- resolve(response.data);
95
- })
96
- .catch((error) => {
97
- reject(error);
98
- });
98
+ /**
99
+ * Get integrations list
100
+ * @param {Array<String>} filter The filter used to select the integration
101
+ * @param {String} type The type of the integration
102
+ * @param {String} version The version to be retrieved
103
+ * @param {Boolean} includeSupportedCapabilities If true, the supported capabilities will be included in the response
104
+ * @param {String} token Authorization token
105
+ */
106
+ export const getIntegrationsList = (
107
+ filter,
108
+ type,
109
+ version,
110
+ includeSupportedCapabilities,
111
+ token
112
+ ) => {
113
+ return new Promise(function (resolve, reject) {
114
+ const requestData = {
115
+ includeSupportedCapabilities: includeSupportedCapabilities,
116
+ version: version,
117
+ };
118
+ if (filter) requestData.filter = filter;
119
+ if (type) requestData.type = type;
120
+ let confirmationRequest = axios.post(`api/v1/integrations`, requestData, {
121
+ headers: { authorization: token },
99
122
  });
100
- },
123
+ confirmationRequest
124
+ .then((response) => {
125
+ resolve(response.data);
126
+ })
127
+ .catch((error) => {
128
+ reject(error);
129
+ });
130
+ });
131
+ };
101
132
 
102
- /**
103
- * Get integrations list
104
- * @param {Array<String>} filter The filter used to select the integration
105
- * @param {String} type The type of the integration
106
- * @param {String} version The version to be retrieved
107
- * @param {Boolean} includeSupportedCapabilities If true, the supported capabilities will be included in the response
108
- * @param {String} token Authorization token
109
- */
110
- getIntegrationsList: (
111
- filter,
112
- type,
113
- version,
114
- includeSupportedCapabilities,
115
- token
116
- ) => {
117
- return new Promise(function (resolve, reject) {
118
- const requestData = {
119
- includeSupportedCapabilities: includeSupportedCapabilities,
120
- version: version,
121
- };
122
- if (filter) requestData.filter = filter;
123
- if (type) requestData.type = type;
124
- let confirmationRequest = axios.post(`api/v1/integrations`, requestData, {
133
+ /**
134
+ * Get content information by Url
135
+ * @param {String} url The training url
136
+ * @param {String} verb The verb
137
+ * @param {String} token Authorization token
138
+ */
139
+ export const getContentInformationByUrl = (url, verb, token) => {
140
+ return new Promise(function (resolve, reject) {
141
+ const requestData = {
142
+ url: url,
143
+ verb: verb,
144
+ };
145
+ let confirmationRequest = axios.post(
146
+ `api/v1/contentproviders/getcontentinformationbyurl`,
147
+ requestData,
148
+ {
125
149
  headers: { authorization: token },
150
+ }
151
+ );
152
+ confirmationRequest
153
+ .then((response) => {
154
+ resolve(response.data);
155
+ })
156
+ .catch((error) => {
157
+ reject(error);
126
158
  });
127
- confirmationRequest
128
- .then((response) => {
129
- resolve(response.data);
130
- })
131
- .catch((error) => {
132
- reject(error);
133
- });
134
- });
135
- },
159
+ });
160
+ };
136
161
 
137
- /**
138
- * Get content information by Url
139
- * @param {String} url The training url
140
- * @param {String} verb The verb
141
- * @param {String} token Authorization token
142
- */
143
- getContentInformationByUrl: (url, verb, token) => {
144
- return new Promise(function (resolve, reject) {
145
- const requestData = {
146
- url: url,
147
- verb: verb,
148
- };
149
- let confirmationRequest = axios.post(
150
- `api/v1/contentproviders/getcontentinformationbyurl`,
151
- requestData,
152
- {
153
- headers: { authorization: token },
154
- }
155
- );
156
- confirmationRequest
157
- .then((response) => {
158
- resolve(response.data);
159
- })
160
- .catch((error) => {
161
- reject(error);
162
- });
162
+ /**
163
+ * Get content information by url from the browser instead of the backend
164
+ * @param {String} url
165
+ * @returns {Object}
166
+ */
167
+ export const getContentInformationByUrlFromBrowser = (url) => {
168
+ return new Promise(function (resolve, reject) {
169
+ let domain = new URL(url);
170
+ let instance = axiosLib.create({
171
+ baseURL: domain.origin,
163
172
  });
164
- },
165
-
166
- /**
167
- * Get content information by url from the browser instead of the backend
168
- * @param {String} url
169
- * @returns {Object}
170
- */
171
- getContentInformationByUrlFromBrowser: (url) => {
172
- return new Promise(function (resolve, reject) {
173
- let domain = new URL(url);
174
- let instance = axiosLib.create({
175
- baseURL: domain.origin,
176
- });
177
- let confirmationRequest = instance.get(domain.pathname, {
178
- headers: {
179
- "Access-Control-Allow-Origin": "*",
180
- "Access-Control-Allow-Headers":
181
- "Authorization, Origin, X-Requested-With, Content-Type, Accept",
182
- Accept:
183
- "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
184
- "Accept-Encoding": "gzip, deflate, br",
185
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
186
- "User-Agent": "Mozilla/5.0",
187
- },
188
- });
189
- confirmationRequest
190
- .then((response) => {
191
- //get the reading time
192
- const getReadingTime = (text) => {
193
- const wpm = 225;
194
- const words = text.trim().split(/\s+/).length;
195
- return Math.ceil(words / wpm);
196
- };
173
+ let confirmationRequest = instance.get(domain.pathname, {
174
+ headers: {
175
+ "Access-Control-Allow-Origin": "*",
176
+ "Access-Control-Allow-Headers":
177
+ "Authorization, Origin, X-Requested-With, Content-Type, Accept",
178
+ Accept:
179
+ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
180
+ "Accept-Encoding": "gzip, deflate, br",
181
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
182
+ "User-Agent": "Mozilla/5.0",
183
+ },
184
+ });
185
+ confirmationRequest
186
+ .then((response) => {
187
+ //get the reading time
188
+ const getReadingTime = (text) => {
189
+ const wpm = 225;
190
+ const words = text.trim().split(/\s+/).length;
191
+ return Math.ceil(words / wpm);
192
+ };
197
193
 
198
- let document = htmlParser.parse(response.responseText);
199
- let duration = getReadingTime(htmlToText(response.responseText));
200
- let title = document.querySelector("title")?.rawText;
201
- let description = "";
202
- const descriptionEl = document.querySelector("meta");
203
- try {
204
- if (descriptionEl) {
205
- const descriptionParentNode = descriptionEl.parentNode;
206
- if (descriptionParentNode) {
207
- const descriptionChildNodes = descriptionParentNode.childNodes;
208
- if (descriptionChildNodes) {
209
- const descriptionRawAttr = descriptionChildNodes.find(
210
- (item) => item.rawAttrs.includes("description")
211
- );
212
- if (descriptionRawAttr) {
213
- const descriptionContent =
214
- descriptionRawAttr.rawAttrs.substring(
215
- descriptionRawAttr.rawAttrs.indexOf("content=") + 9
216
- );
217
- description = descriptionContent.substring(
218
- 0,
219
- descriptionContent.length - 1
194
+ let document = htmlParser.parse(response.responseText);
195
+ let duration = getReadingTime(htmlToText(response.responseText));
196
+ let title = document.querySelector("title")?.rawText;
197
+ let description = "";
198
+ const descriptionEl = document.querySelector("meta");
199
+ try {
200
+ if (descriptionEl) {
201
+ const descriptionParentNode = descriptionEl.parentNode;
202
+ if (descriptionParentNode) {
203
+ const descriptionChildNodes = descriptionParentNode.childNodes;
204
+ if (descriptionChildNodes) {
205
+ const descriptionRawAttr = descriptionChildNodes.find((item) =>
206
+ item.rawAttrs.includes("description")
207
+ );
208
+ if (descriptionRawAttr) {
209
+ const descriptionContent =
210
+ descriptionRawAttr.rawAttrs.substring(
211
+ descriptionRawAttr.rawAttrs.indexOf("content=") + 9
220
212
  );
221
- }
213
+ description = descriptionContent.substring(
214
+ 0,
215
+ descriptionContent.length - 1
216
+ );
222
217
  }
223
218
  }
224
219
  }
225
- } finally {
226
- resolve({
227
- description: description,
228
- duration: duration,
229
- icon: `http://www.google.com/s2/favicons?sz=128&domain_url=${pathArray[2]}`,
230
- title: title ? title.trim() : url,
231
- type: 0,
232
- internal: true,
233
- });
234
220
  }
235
- })
236
- .catch((error) => {
237
- reject(new Error(errorToString(error)));
238
- });
239
- });
240
- },
241
-
242
- /**
243
- * Get enabled content providers
244
- * @param {String} userid
245
- * @param {String} verb The verb
246
- * @param {String} token Authorization token
247
- */
248
- getEnabledContentProviders: (userId, token) => {
249
- return new Promise(function (resolve, reject) {
250
- let confirmationRequest = axios.get(
251
- `api/v1/contentproviders/getenabledcontentproviders/${userId}`,
252
- {
253
- headers: { authorization: token },
221
+ } finally {
222
+ resolve({
223
+ description: description,
224
+ duration: duration,
225
+ icon: `http://www.google.com/s2/favicons?sz=128&domain_url=${pathArray[2]}`,
226
+ title: title ? title.trim() : url,
227
+ type: 0,
228
+ internal: true,
229
+ });
254
230
  }
255
- );
256
- confirmationRequest
257
- .then((response) => {
258
- resolve(response.data);
259
- })
260
- .catch((error) => {
261
- reject(error);
262
- });
263
- });
264
- },
231
+ })
232
+ .catch((error) => {
233
+ reject(new Error(errorToString(error)));
234
+ });
235
+ });
236
+ };
265
237
 
266
- /**
267
- * Publish integration
268
- * @param {String} id The id of the integration to be published
269
- * @param {String} token Authorization token
270
- */
271
- publishIntegration: (id, token) => {
272
- return new Promise(function (resolve, reject) {
273
- let confirmationRequest = axios.post(
274
- `api/v1/integrations/publish/${id}`,
275
- {},
276
- {
277
- headers: { authorization: token },
278
- }
279
- );
280
- confirmationRequest
281
- .then((response) => {
282
- resolve(response.data);
283
- })
284
- .catch((error) => {
285
- reject(error);
286
- });
287
- });
288
- },
238
+ /**
239
+ * Get enabled content providers
240
+ * @param {String} userid
241
+ * @param {String} verb The verb
242
+ * @param {String} token Authorization token
243
+ */
244
+ export const getEnabledContentProviders = (userId, token) => {
245
+ return new Promise(function (resolve, reject) {
246
+ let confirmationRequest = axios.get(
247
+ `api/v1/contentproviders/getenabledcontentproviders/${userId}`,
248
+ {
249
+ headers: { authorization: token },
250
+ }
251
+ );
252
+ confirmationRequest
253
+ .then((response) => {
254
+ resolve(response.data);
255
+ })
256
+ .catch((error) => {
257
+ reject(error);
258
+ });
259
+ });
260
+ };
289
261
 
290
- /**
291
- * Set integration information
292
- * @param {String} id The id of the integration to be updated
293
- * @param {Object} data Data used to update the integration
294
- * @param {String} token Authorization token
295
- */
296
- setIntegrationInformation: (id, data, token) => {
297
- return new Promise(function (resolve, reject) {
298
- const requestData = {
299
- data: data,
300
- };
301
- let confirmationRequest = axios.post(
302
- `api/v1/integrations/${id}`,
303
- requestData,
304
- {
305
- headers: { authorization: token },
306
- }
307
- );
308
- confirmationRequest
309
- .then((response) => {
310
- resolve(response.data);
311
- })
312
- .catch((error) => {
313
- reject(error);
314
- });
315
- });
316
- },
262
+ /**
263
+ * Publish integration
264
+ * @param {String} id The id of the integration to be published
265
+ * @param {String} token Authorization token
266
+ */
267
+ export const publishIntegration = (id, token) => {
268
+ return new Promise(function (resolve, reject) {
269
+ let confirmationRequest = axios.post(
270
+ `api/v1/integrations/publish/${id}`,
271
+ {},
272
+ {
273
+ headers: { authorization: token },
274
+ }
275
+ );
276
+ confirmationRequest
277
+ .then((response) => {
278
+ resolve(response.data);
279
+ })
280
+ .catch((error) => {
281
+ reject(error);
282
+ });
283
+ });
284
+ };
317
285
 
318
- /**
319
- * Set default integration
320
- * @param {String} id The id of the integration to be set as default
321
- * @param {String} token Authorization token
322
- */
323
- setDefaultIntegration: (id, token) => {
324
- return new Promise(function (resolve, reject) {
325
- let confirmationRequest = axios.post(
326
- `api/v1/integrations/${id}/default`,
327
- "",
328
- {
329
- headers: { authorization: token },
330
- }
331
- );
332
- confirmationRequest
333
- .then((response) => {
334
- resolve(response.data);
335
- })
336
- .catch((error) => {
337
- reject(error);
338
- });
339
- });
340
- },
286
+ /**
287
+ * Set integration information
288
+ * @param {String} id The id of the integration to be updated
289
+ * @param {Object} data Data used to update the integration
290
+ * @param {String} token Authorization token
291
+ */
292
+ export const setIntegrationInformation = (id, data, token) => {
293
+ return new Promise(function (resolve, reject) {
294
+ const requestData = {
295
+ data: data,
296
+ };
297
+ let confirmationRequest = axios.post(
298
+ `api/v1/integrations/${id}`,
299
+ requestData,
300
+ {
301
+ headers: { authorization: token },
302
+ }
303
+ );
304
+ confirmationRequest
305
+ .then((response) => {
306
+ resolve(response.data);
307
+ })
308
+ .catch((error) => {
309
+ reject(error);
310
+ });
311
+ });
312
+ };
313
+
314
+ /**
315
+ * Set default integration
316
+ * @param {String} id The id of the integration to be set as default
317
+ * @param {String} token Authorization token
318
+ */
319
+ export const setDefaultIntegration = (id, token) => {
320
+ return new Promise(function (resolve, reject) {
321
+ let confirmationRequest = axios.post(
322
+ `api/v1/integrations/${id}/default`,
323
+ "",
324
+ {
325
+ headers: { authorization: token },
326
+ }
327
+ );
328
+ confirmationRequest
329
+ .then((response) => {
330
+ resolve(response.data);
331
+ })
332
+ .catch((error) => {
333
+ reject(error);
334
+ });
335
+ });
341
336
  };