@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.
- package/LICENSE +201 -0
- package/index.js +22 -0
- package/lib/actionNotifications.js +243 -0
- package/lib/address.js +29 -0
- package/lib/axios.js +216 -0
- package/lib/config.js +77 -0
- package/lib/dashboard.js +75 -0
- package/lib/departmentTrainingPlans.js +163 -0
- package/lib/groups.js +314 -0
- package/lib/integration.js +337 -0
- package/lib/integrationConfiguration.js +94 -0
- package/lib/integrations/contentgenerator.js +79 -0
- package/lib/logger.js +61 -0
- package/lib/role.js +266 -0
- package/lib/roleTemplate.js +243 -0
- package/lib/skill.js +338 -0
- package/lib/skillAssessmentTestingSession.js +143 -0
- package/lib/skillAssessments.js +139 -0
- package/lib/skillTemplate.js +248 -0
- package/lib/teams.js +277 -0
- package/lib/templateDocument.js +131 -0
- package/lib/templatePhase.js +134 -0
- package/lib/templateRelease.js +98 -0
- package/lib/templates.js +159 -0
- package/lib/tenants.js +60 -0
- package/lib/trainingPlanTemplate.js +215 -0
- package/lib/trainingPlans.js +267 -0
- package/lib/userInformation.js +89 -0
- package/lib/users.js +622 -0
- package/lib/utils.js +27 -0
- package/package.json +24 -0
package/lib/groups.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Group sepcific requests
|
|
3
|
+
//
|
|
4
|
+
import axios from "./axios";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
axios: axios,
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Add permissions to group
|
|
11
|
+
* @param {String} groupId The group Id
|
|
12
|
+
* @param {Array<String>} permissions The permissions to be added
|
|
13
|
+
* @param {String} authToken - Authentication token
|
|
14
|
+
*/
|
|
15
|
+
addPermissionsToGroup(groupId, permissions, authToken) {
|
|
16
|
+
return new Promise(function (resolve, reject) {
|
|
17
|
+
const request = axios.post(
|
|
18
|
+
`api/v1/groups/permissions/add`,
|
|
19
|
+
{
|
|
20
|
+
groupId: groupId,
|
|
21
|
+
permissions: permissions,
|
|
22
|
+
},
|
|
23
|
+
{ headers: { authorization: authToken } }
|
|
24
|
+
);
|
|
25
|
+
request
|
|
26
|
+
.then((response) => {
|
|
27
|
+
resolve(response.data);
|
|
28
|
+
})
|
|
29
|
+
.catch((error) => {
|
|
30
|
+
reject(error);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Add users to group
|
|
37
|
+
* @param {String} groupId The group Id
|
|
38
|
+
* @param {Array<String>} users The users to be added
|
|
39
|
+
* @param {String} authToken - Authentication token
|
|
40
|
+
*/
|
|
41
|
+
addUsersToGroup(groupId, users, authToken) {
|
|
42
|
+
return new Promise(function (resolve, reject) {
|
|
43
|
+
const request = axios.post(
|
|
44
|
+
`api/v1/groups/users/add`,
|
|
45
|
+
{
|
|
46
|
+
groupId: groupId,
|
|
47
|
+
users: users,
|
|
48
|
+
},
|
|
49
|
+
{ headers: { authorization: authToken } }
|
|
50
|
+
);
|
|
51
|
+
request
|
|
52
|
+
.then((response) => {
|
|
53
|
+
resolve(response.data);
|
|
54
|
+
})
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
reject(error);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create group
|
|
63
|
+
* @param {String} name The name of the group
|
|
64
|
+
* @param {String} description The description of the group
|
|
65
|
+
* @param {String} authToken The authorization token
|
|
66
|
+
*/
|
|
67
|
+
createGroup(name, description, authToken) {
|
|
68
|
+
return new Promise(function (resolve, reject) {
|
|
69
|
+
const request = axios.post(
|
|
70
|
+
`api/v1/groups/group`,
|
|
71
|
+
{
|
|
72
|
+
name: name,
|
|
73
|
+
description: description,
|
|
74
|
+
},
|
|
75
|
+
{ headers: { authorization: authToken } }
|
|
76
|
+
);
|
|
77
|
+
request
|
|
78
|
+
.then((response) => {
|
|
79
|
+
resolve(response.data);
|
|
80
|
+
})
|
|
81
|
+
.catch((error) => {
|
|
82
|
+
reject(error);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Delete group
|
|
89
|
+
* @param {String} groupId The group to be deleted
|
|
90
|
+
* @param {String} defaultGroupId The default group all the users will be moved to
|
|
91
|
+
* @param {String} authToken The authentication token
|
|
92
|
+
*/
|
|
93
|
+
deleteGroup(groupId, defaultGroupId, authToken) {
|
|
94
|
+
return new Promise(function (resolve, reject) {
|
|
95
|
+
const request = axios.delete(`api/v1/groups/delete`, {
|
|
96
|
+
headers: { authorization: authToken },
|
|
97
|
+
data: {
|
|
98
|
+
id: groupId,
|
|
99
|
+
defaultGroupId: defaultGroupId,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
request
|
|
103
|
+
.then((response) => {
|
|
104
|
+
resolve(response.data);
|
|
105
|
+
})
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
reject(error);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get all permissions
|
|
114
|
+
*
|
|
115
|
+
* @param {String} authToken The authentication token
|
|
116
|
+
*/
|
|
117
|
+
getAllPermissions(authToken) {
|
|
118
|
+
return new Promise(function (resolve, reject) {
|
|
119
|
+
const request = axios.get(`api/v1/groups/permissions/getAllPermissions`, {
|
|
120
|
+
headers: { authorization: authToken },
|
|
121
|
+
});
|
|
122
|
+
request
|
|
123
|
+
.then((response) => {
|
|
124
|
+
resolve(response.data);
|
|
125
|
+
})
|
|
126
|
+
.catch((error) => {
|
|
127
|
+
reject(error);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get group by Id
|
|
134
|
+
* @param {*} groupId The group Id
|
|
135
|
+
* @param {String} authToken The authentication token
|
|
136
|
+
*/
|
|
137
|
+
getGroupById(groupId, authToken) {
|
|
138
|
+
return new Promise(function (resolve, reject) {
|
|
139
|
+
const request = axios.get(`api/v1/groups/group/${groupId}`, {
|
|
140
|
+
headers: { authorization: authToken },
|
|
141
|
+
});
|
|
142
|
+
request
|
|
143
|
+
.then((response) => {
|
|
144
|
+
resolve(response.data);
|
|
145
|
+
})
|
|
146
|
+
.catch((error) => {
|
|
147
|
+
reject(error);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get groups for current tenant
|
|
154
|
+
* @param {*} authToken The authentication token
|
|
155
|
+
*/
|
|
156
|
+
getGroups(authToken) {
|
|
157
|
+
return new Promise(function (resolve, reject) {
|
|
158
|
+
const request = axios.get(`api/v1/groups/`, {
|
|
159
|
+
headers: { authorization: authToken },
|
|
160
|
+
});
|
|
161
|
+
request
|
|
162
|
+
.then((response) => {
|
|
163
|
+
resolve(response.data);
|
|
164
|
+
})
|
|
165
|
+
.catch((error) => {
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get current user permissions
|
|
173
|
+
* @param {*} authToken The authentication token
|
|
174
|
+
*/
|
|
175
|
+
getUserPermissions(authToken) {
|
|
176
|
+
return new Promise(function (resolve, reject) {
|
|
177
|
+
const request = axios.get(`api/v1/groups/users/getuserpermissions`, {
|
|
178
|
+
headers: { authorization: authToken },
|
|
179
|
+
});
|
|
180
|
+
request
|
|
181
|
+
.then((response) => {
|
|
182
|
+
resolve(response.data);
|
|
183
|
+
})
|
|
184
|
+
.catch((error) => {
|
|
185
|
+
reject(error);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Build in permissions
|
|
192
|
+
*/
|
|
193
|
+
permissions: {
|
|
194
|
+
ADMIN_AUTHOR_CONTENT: "5ea3d1152839450e16e72bba",
|
|
195
|
+
ADMIN_PROMOTE_CONTENT: "5ea3d10bea252025c8ec351b",
|
|
196
|
+
ADMIN_MANAGE_CONTENT_PROVIDERS: "61970935cee185acf08111f6",
|
|
197
|
+
AUTHOR_CONTENT: "5fac210560e43de7c6b4a208",
|
|
198
|
+
MANAGE_BILLING: "5e1570cd03f676213bfdcd08",
|
|
199
|
+
MANAGE_CONTENT_PROVIDERS: "5f0fa12f16a720fde58ea820",
|
|
200
|
+
MANAGE_GROUPS: "5dd612fe59e518ac87b8cf8e",
|
|
201
|
+
MANAGE_OWN_PROFILE_INFORMATION_AUTO_APP: "5fac210e7e6539d37a897c94",
|
|
202
|
+
MANAGE_ORGANIZATION_INFORMATION: "5dd612d5338ea9a6ae6326da",
|
|
203
|
+
MANAGE_OWN_SKILL_SET_AUTO_APPROVE: "5fac21164351c6727a34cd4e",
|
|
204
|
+
MANAGE_SETTINGS: "5e1570e087d836dc77888a5f",
|
|
205
|
+
MANAGE_TEAM_INFORMATION_AUTO_APPROVE: "5fac211e6c8f874bd7137b98",
|
|
206
|
+
MANAGE_TEAMS: "5dd61314afc2455a89b1a37b",
|
|
207
|
+
MANAGE_USERS: "5dd612e40f0bc559c41a2b29",
|
|
208
|
+
PROMOTE_CONTENT: "5fac2126427ce31f8a92c0cb",
|
|
209
|
+
MANAGE_PLAN_TEMPLATES: "5dd61305a73c68b44c3f0827",
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* Remove permissions from group
|
|
213
|
+
* @param {String} groupId The group Id
|
|
214
|
+
* @param {Array<String>} permissions The permissions to be removed from the group
|
|
215
|
+
* @param {String} authToken The authentication token
|
|
216
|
+
*/
|
|
217
|
+
removePermissionsFromGroup(groupId, permissions, authToken) {
|
|
218
|
+
return new Promise(function (resolve, reject) {
|
|
219
|
+
const request = axios.post(
|
|
220
|
+
`api/v1/groups/permissions/remove/`,
|
|
221
|
+
{
|
|
222
|
+
groupId: groupId,
|
|
223
|
+
permissions: permissions,
|
|
224
|
+
},
|
|
225
|
+
{ headers: { authorization: authToken } }
|
|
226
|
+
);
|
|
227
|
+
request
|
|
228
|
+
.then((response) => {
|
|
229
|
+
resolve(response.data);
|
|
230
|
+
})
|
|
231
|
+
.catch((error) => {
|
|
232
|
+
reject(error);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Remove users from group
|
|
239
|
+
* @param {String} groupId The group Id
|
|
240
|
+
* @param {Array<String>} users The users to be removed from the group
|
|
241
|
+
* @param {String} authToken The authentication token
|
|
242
|
+
*/
|
|
243
|
+
removeUsersFromGroup(groupId, users, authToken) {
|
|
244
|
+
return new Promise(function (resolve, reject) {
|
|
245
|
+
const request = axios.post(
|
|
246
|
+
`api/v1/groups/users/remove/`,
|
|
247
|
+
{
|
|
248
|
+
groupId: groupId,
|
|
249
|
+
users: users,
|
|
250
|
+
},
|
|
251
|
+
{ headers: { authorization: authToken } }
|
|
252
|
+
);
|
|
253
|
+
request
|
|
254
|
+
.then((response) => {
|
|
255
|
+
resolve(response.data);
|
|
256
|
+
})
|
|
257
|
+
.catch((error) => {
|
|
258
|
+
reject(error);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
/*
|
|
264
|
+
* Set group as defualt
|
|
265
|
+
* @param {String} groupId The group Id
|
|
266
|
+
* @param {String} authToken The authentication token
|
|
267
|
+
*/
|
|
268
|
+
setDefault(groupId, authToken) {
|
|
269
|
+
return new Promise(function (resolve, reject) {
|
|
270
|
+
const request = axios.put(
|
|
271
|
+
`api/v1/groups/setDefault/`,
|
|
272
|
+
{
|
|
273
|
+
id: groupId,
|
|
274
|
+
},
|
|
275
|
+
{ headers: { authorization: authToken } }
|
|
276
|
+
);
|
|
277
|
+
request
|
|
278
|
+
.then((response) => {
|
|
279
|
+
resolve(response.data);
|
|
280
|
+
})
|
|
281
|
+
.catch((error) => {
|
|
282
|
+
reject(error);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Update group
|
|
289
|
+
* @param {String} groupId The group Id
|
|
290
|
+
* @param {string} name The updated name of the group
|
|
291
|
+
* @param {string} description The updated description of the group
|
|
292
|
+
* @param {String} authToken The authentication token
|
|
293
|
+
*/
|
|
294
|
+
updateGroup(groupId, name, description, authToken) {
|
|
295
|
+
return new Promise(function (resolve, reject) {
|
|
296
|
+
const request = axios.patch(
|
|
297
|
+
`api/v1/groups/group/`,
|
|
298
|
+
{
|
|
299
|
+
id: groupId,
|
|
300
|
+
name: name,
|
|
301
|
+
description: description,
|
|
302
|
+
},
|
|
303
|
+
{ headers: { authorization: authToken } }
|
|
304
|
+
);
|
|
305
|
+
request
|
|
306
|
+
.then((response) => {
|
|
307
|
+
resolve(response.data);
|
|
308
|
+
})
|
|
309
|
+
.catch((error) => {
|
|
310
|
+
reject(error);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
};
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
import axios, { errorToString } from "./axios";
|
|
3
|
+
import axiosLib from "axios";
|
|
4
|
+
import htmlParser from "node-html-parser";
|
|
5
|
+
import htmlToText from "html2plaintext";
|
|
6
|
+
|
|
7
|
+
export default {
|
|
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
|
+
});
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
|
|
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
|
+
},
|
|
45
|
+
});
|
|
46
|
+
request
|
|
47
|
+
.then((response) => {
|
|
48
|
+
resolve(response.data);
|
|
49
|
+
})
|
|
50
|
+
.catch((error) => {
|
|
51
|
+
reject(error);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
|
|
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}`, {
|
|
65
|
+
headers: { authorization: token },
|
|
66
|
+
data: data,
|
|
67
|
+
});
|
|
68
|
+
request
|
|
69
|
+
.then((response) => {
|
|
70
|
+
resolve(response.data);
|
|
71
|
+
})
|
|
72
|
+
.catch((error) => {
|
|
73
|
+
reject(error);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
|
|
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
|
+
});
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
|
|
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, {
|
|
125
|
+
headers: { authorization: token },
|
|
126
|
+
});
|
|
127
|
+
confirmationRequest
|
|
128
|
+
.then((response) => {
|
|
129
|
+
resolve(response.data);
|
|
130
|
+
})
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
reject(error);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
|
|
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
|
+
});
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
//get content information by url from the browser instead of the backend
|
|
167
|
+
getContentInformationByUrlFromBrowser(url) {
|
|
168
|
+
return new Promise(function (resolve, reject) {
|
|
169
|
+
let domain = new URL(url);
|
|
170
|
+
let instance = axiosLib.create({
|
|
171
|
+
baseURL: domain.origin,
|
|
172
|
+
});
|
|
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
|
+
};
|
|
193
|
+
|
|
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(
|
|
206
|
+
(item) => item.rawAttrs.includes("description")
|
|
207
|
+
);
|
|
208
|
+
if (descriptionRawAttr) {
|
|
209
|
+
const descriptionContent =
|
|
210
|
+
descriptionRawAttr.rawAttrs.substring(
|
|
211
|
+
descriptionRawAttr.rawAttrs.indexOf("content=") + 9
|
|
212
|
+
);
|
|
213
|
+
description = descriptionContent.substring(
|
|
214
|
+
0,
|
|
215
|
+
descriptionContent.length - 1
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
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
|
+
});
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
.catch((error) => {
|
|
233
|
+
reject(new Error(errorToString(error)));
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get enabled content providers
|
|
240
|
+
* @param {String} userid
|
|
241
|
+
* @param {String} verb The verb
|
|
242
|
+
* @param {String} token Authorization token
|
|
243
|
+
*/
|
|
244
|
+
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
|
+
},
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Publish integration
|
|
264
|
+
* @param {String} id The id of the integration to be published
|
|
265
|
+
* @param {String} token Authorization token
|
|
266
|
+
*/
|
|
267
|
+
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
|
+
},
|
|
285
|
+
|
|
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
|
+
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
|
+
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
|
+
});
|
|
336
|
+
},
|
|
337
|
+
};
|