@stackfactor/client-api 1.1.148 → 1.1.150

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.
Files changed (54) hide show
  1. package/dist/actionNotifications.js +73 -0
  2. package/dist/address.js +22 -0
  3. package/dist/aiAssistant.js +134 -0
  4. package/dist/avatar.js +32 -0
  5. package/dist/axiosClient.js +89 -0
  6. package/dist/cjs/departmentTrainingPlans.d.ts +4 -4
  7. package/dist/cjs/departmentTrainingPlans.js +2 -2
  8. package/dist/cjs/departmentTrainingPlans.js.map +1 -1
  9. package/dist/cjs/integration.d.ts +2 -2
  10. package/dist/cjs/integration.d.ts.map +1 -1
  11. package/dist/cjs/integration.js +1 -1
  12. package/dist/cjs/integration.js.map +1 -1
  13. package/dist/cjs/integrationConfiguration.d.ts +2 -2
  14. package/dist/cjs/integrationConfiguration.js +1 -1
  15. package/dist/config.js +63 -0
  16. package/dist/constants.js +94 -0
  17. package/dist/dashboard.js +74 -0
  18. package/dist/departmentTrainingPlans.js +154 -0
  19. package/dist/esm/departmentTrainingPlans.d.ts +4 -4
  20. package/dist/esm/departmentTrainingPlans.js +2 -2
  21. package/dist/esm/departmentTrainingPlans.js.map +1 -1
  22. package/dist/esm/integration.d.ts +2 -2
  23. package/dist/esm/integration.d.ts.map +1 -1
  24. package/dist/esm/integration.js +1 -1
  25. package/dist/esm/integration.js.map +1 -1
  26. package/dist/esm/integrationConfiguration.d.ts +2 -2
  27. package/dist/esm/integrationConfiguration.js +1 -1
  28. package/dist/exports.js +77 -0
  29. package/dist/groups.js +273 -0
  30. package/dist/index.js +77 -0
  31. package/dist/integration.js +319 -0
  32. package/dist/integrationConfiguration.js +86 -0
  33. package/dist/integrations/contentGenerator.js +70 -0
  34. package/dist/learningContent.js +394 -0
  35. package/dist/learningPath.js +205 -0
  36. package/dist/logger.js +57 -0
  37. package/dist/microSkillsQuizes.js +53 -0
  38. package/dist/quotas.js +50 -0
  39. package/dist/role.js +363 -0
  40. package/dist/roleTemplate.js +236 -0
  41. package/dist/security.js +79 -0
  42. package/dist/skill.js +439 -0
  43. package/dist/skillAssessmentTestingSession.js +156 -0
  44. package/dist/skillAssessments.js +156 -0
  45. package/dist/skillTemplate.js +281 -0
  46. package/dist/talentTransfromation.js +100 -0
  47. package/dist/teams.js +252 -0
  48. package/dist/tenants.js +52 -0
  49. package/dist/trainingPlans.js +308 -0
  50. package/dist/trainingPlansProficiencyLevels.js +98 -0
  51. package/dist/userInformation.js +81 -0
  52. package/dist/users.js +694 -0
  53. package/dist/utils.js +65 -0
  54. package/package.json +1 -1
package/dist/groups.js ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const axiosClient_1 = require("./axiosClient");
4
+ /**
5
+ * Add permissions to group
6
+ * @param {String} groupId The group Id
7
+ * @param {Array<String>} permissions The permissions to be added
8
+ * @param {String} authToken - Authentication token
9
+ * @returns {Promise<Object>}
10
+ */
11
+ const addPermissionsToGroup = (groupId, permissions, authToken) => {
12
+ return new Promise((resolve, reject) => {
13
+ const request = axiosClient_1.client.post(`api/v1/groups/permissions/add`, {
14
+ groupId: groupId,
15
+ permissions: permissions,
16
+ }, { headers: { authorization: authToken } });
17
+ request
18
+ .then((response) => {
19
+ resolve(response.data);
20
+ })
21
+ .catch((error) => {
22
+ reject(error);
23
+ });
24
+ });
25
+ };
26
+ /**
27
+ * Add users to group
28
+ * @param {String} groupId The group Id
29
+ * @param {Array<String>} users The users to be added
30
+ * @param {String} authToken - Authentication token
31
+ * @returns {Promise<Object>}
32
+ */
33
+ const addUsersToGroup = (groupId, users, authToken) => {
34
+ return new Promise((resolve, reject) => {
35
+ const request = axiosClient_1.client.post(`api/v1/groups/users/add`, {
36
+ groupId: groupId,
37
+ users: users,
38
+ }, { headers: { authorization: authToken } });
39
+ request
40
+ .then((response) => {
41
+ resolve(response.data);
42
+ })
43
+ .catch((error) => {
44
+ reject(error);
45
+ });
46
+ });
47
+ };
48
+ /**
49
+ * Create group
50
+ * @param {String} name The name of the group
51
+ * @param {String} description The description of the group
52
+ * @param {String} authToken The authorization token
53
+ * @returns {Promise<Object>}
54
+ */
55
+ const createGroup = (name, description, authToken) => {
56
+ return new Promise((resolve, reject) => {
57
+ const request = axiosClient_1.client.post(`api/v1/groups/group`, {
58
+ name: name,
59
+ description: description,
60
+ }, { headers: { authorization: authToken } });
61
+ request
62
+ .then((response) => {
63
+ resolve(response.data);
64
+ })
65
+ .catch((error) => {
66
+ reject(error);
67
+ });
68
+ });
69
+ };
70
+ /**
71
+ * Delete group
72
+ * @param {String} groupId The group to be deleted
73
+ * @param {String} defaultGroupId The default group all the users will be moved to
74
+ * @param {String} authToken The authentication token
75
+ * @returns {Promise<Object>}
76
+ */
77
+ const deleteGroup = (groupId, defaultGroupId, authToken) => {
78
+ return new Promise((resolve, reject) => {
79
+ const request = axiosClient_1.client.delete(`api/v1/groups/delete`, {
80
+ headers: { authorization: authToken },
81
+ data: {
82
+ id: groupId,
83
+ defaultGroupId: defaultGroupId,
84
+ },
85
+ });
86
+ request
87
+ .then((response) => {
88
+ resolve(response.data);
89
+ })
90
+ .catch((error) => {
91
+ reject(error);
92
+ });
93
+ });
94
+ };
95
+ /**
96
+ * Get all permissions
97
+ * @param {String} authToken The authentication token
98
+ * @returns {Promise<Object>}
99
+ */
100
+ const getAllPermissions = (authToken) => {
101
+ return new Promise((resolve, reject) => {
102
+ const request = axiosClient_1.client.get(`api/v1/groups/permissions/getAllPermissions`, {
103
+ headers: { authorization: authToken },
104
+ });
105
+ request
106
+ .then((response) => {
107
+ resolve(response.data);
108
+ })
109
+ .catch((error) => {
110
+ reject(error);
111
+ });
112
+ });
113
+ };
114
+ /**
115
+ * Get group by Id
116
+ * @param {String} groupId The group Id
117
+ * @param {String} authToken The authentication token
118
+ * @returns {Promise<Object>}
119
+ */
120
+ const getGroupById = (groupId, authToken) => {
121
+ return new Promise((resolve, reject) => {
122
+ const request = axiosClient_1.client.get(`api/v1/groups/group/${groupId}`, {
123
+ headers: { authorization: authToken },
124
+ });
125
+ request
126
+ .then((response) => {
127
+ resolve(response.data);
128
+ })
129
+ .catch((error) => {
130
+ reject(error);
131
+ });
132
+ });
133
+ };
134
+ /**
135
+ * Get groups for current tenant
136
+ * @param {String} authToken The authentication token
137
+ * @returns {Promise<Object>}
138
+ */
139
+ const getGroups = (authToken) => {
140
+ return new Promise((resolve, reject) => {
141
+ const request = axiosClient_1.client.get(`api/v1/groups/`, {
142
+ headers: { authorization: authToken },
143
+ });
144
+ request
145
+ .then((response) => {
146
+ resolve(response.data);
147
+ })
148
+ .catch((error) => {
149
+ reject(error);
150
+ });
151
+ });
152
+ };
153
+ /**
154
+ * Get current user permissions
155
+ * @param {String} authToken The authentication token
156
+ * @returns {Promise<Object>}
157
+ */
158
+ const getUserPermissions = (authToken) => {
159
+ return new Promise((resolve, reject) => {
160
+ const request = axiosClient_1.client.get(`api/v1/groups/users/getuserpermissions`, {
161
+ headers: { authorization: authToken },
162
+ });
163
+ request
164
+ .then((response) => {
165
+ resolve(response.data);
166
+ })
167
+ .catch((error) => {
168
+ reject(error);
169
+ });
170
+ });
171
+ };
172
+ /**
173
+ * Remove permissions from group
174
+ * @param {String} groupId The group Id
175
+ * @param {Array<String>} permissions The permissions to be removed from the group
176
+ * @param {String} authToken The authentication token
177
+ * @returns {Promise<Object>}
178
+ */
179
+ const removePermissionsFromGroup = (groupId, permissions, authToken) => {
180
+ return new Promise((resolve, reject) => {
181
+ const request = axiosClient_1.client.post(`api/v1/groups/permissions/remove/`, {
182
+ groupId: groupId,
183
+ permissions: permissions,
184
+ }, { headers: { authorization: authToken } });
185
+ request
186
+ .then((response) => {
187
+ resolve(response.data);
188
+ })
189
+ .catch((error) => {
190
+ reject(error);
191
+ });
192
+ });
193
+ };
194
+ /**
195
+ * Remove users from group
196
+ * @param {String} groupId The group Id
197
+ * @param {Array<String>} users The users to be removed from the group
198
+ * @param {String} authToken The authentication token
199
+ * @returns {Promise<Object>}
200
+ */
201
+ const removeUsersFromGroup = (groupId, users, authToken) => {
202
+ return new Promise((resolve, reject) => {
203
+ const request = axiosClient_1.client.post(`api/v1/groups/users/remove/`, {
204
+ groupId: groupId,
205
+ users: users,
206
+ }, { headers: { authorization: authToken } });
207
+ request
208
+ .then((response) => {
209
+ resolve(response.data);
210
+ })
211
+ .catch((error) => {
212
+ reject(error);
213
+ });
214
+ });
215
+ };
216
+ /**
217
+ * Set group as default
218
+ * @param {String} groupId The group Id
219
+ * @param {String} authToken The authentication token
220
+ * @returns {Promise<Object>}
221
+ */
222
+ const setDefault = (groupId, authToken) => {
223
+ return new Promise((resolve, reject) => {
224
+ const request = axiosClient_1.client.put(`api/v1/groups/setDefault/`, {
225
+ id: groupId,
226
+ }, { headers: { authorization: authToken } });
227
+ request
228
+ .then((response) => {
229
+ resolve(response.data);
230
+ })
231
+ .catch((error) => {
232
+ reject(error);
233
+ });
234
+ });
235
+ };
236
+ /**
237
+ * Update group
238
+ * @param {String} groupId The group Id
239
+ * @param {String} name The updated name of the group
240
+ * @param {String} description The updated description of the group
241
+ * @param {String} authToken The authentication token
242
+ * @returns {Promise<Object>}
243
+ */
244
+ const updateGroup = (groupId, name, description, authToken) => {
245
+ return new Promise((resolve, reject) => {
246
+ const request = axiosClient_1.client.patch(`api/v1/groups/group/`, {
247
+ id: groupId,
248
+ name: name,
249
+ description: description,
250
+ }, { headers: { authorization: authToken } });
251
+ request
252
+ .then((response) => {
253
+ resolve(response.data);
254
+ })
255
+ .catch((error) => {
256
+ reject(error);
257
+ });
258
+ });
259
+ };
260
+ exports.default = {
261
+ addPermissionsToGroup,
262
+ addUsersToGroup,
263
+ createGroup,
264
+ deleteGroup,
265
+ getAllPermissions,
266
+ getGroupById,
267
+ getGroups,
268
+ getUserPermissions,
269
+ removePermissionsFromGroup,
270
+ removeUsersFromGroup,
271
+ setDefault,
272
+ updateGroup,
273
+ };
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.users = exports.userInformation = exports.trainingPlanProficiencyLevel = exports.trainingPlan = exports.tenant = exports.team = exports.talentTransfromation = exports.skillTemplate = exports.skillAssessmentTestingSession = exports.skillAssessment = exports.skill = exports.shouldReturnError = exports.security = exports.roleTemplate = exports.role = exports.RESPONSE_TYPE = exports.quotas = exports.PERMISSION_DESCRIPTIONS = exports.PERMISSIONS = exports.microSkillsQuizes = exports.logger = exports.learningPath = exports.learningContent = exports.groups = exports.departmentTraingPlans = exports.integrationConfiguration = exports.integration = exports.DOCUMENT_VERSION = exports.getErrorType = exports.getErrorInformation = exports.errorToString = exports.dashboard = exports.contentGenerator = exports.config = exports.client = exports.avatar = exports.aiAssistant = exports.address = exports.actionNotifications = void 0;
7
+ const actionNotifications_1 = __importDefault(require("./actionNotifications"));
8
+ exports.actionNotifications = actionNotifications_1.default;
9
+ const axiosClient_1 = require("./axiosClient");
10
+ Object.defineProperty(exports, "client", { enumerable: true, get: function () { return axiosClient_1.client; } });
11
+ Object.defineProperty(exports, "errorToString", { enumerable: true, get: function () { return axiosClient_1.errorToString; } });
12
+ Object.defineProperty(exports, "getErrorInformation", { enumerable: true, get: function () { return axiosClient_1.getErrorInformation; } });
13
+ Object.defineProperty(exports, "getErrorType", { enumerable: true, get: function () { return axiosClient_1.getErrorType; } });
14
+ Object.defineProperty(exports, "shouldReturnError", { enumerable: true, get: function () { return axiosClient_1.shouldReturnError; } });
15
+ const aiAssistant_1 = __importDefault(require("./aiAssistant"));
16
+ exports.aiAssistant = aiAssistant_1.default;
17
+ const avatar_1 = __importDefault(require("./avatar"));
18
+ exports.avatar = avatar_1.default;
19
+ const address_1 = __importDefault(require("./address"));
20
+ exports.address = address_1.default;
21
+ const config_1 = __importDefault(require("./config"));
22
+ exports.config = config_1.default;
23
+ const constants_1 = require("./constants");
24
+ Object.defineProperty(exports, "DOCUMENT_VERSION", { enumerable: true, get: function () { return constants_1.DOCUMENT_VERSION; } });
25
+ Object.defineProperty(exports, "PERMISSIONS", { enumerable: true, get: function () { return constants_1.PERMISSIONS; } });
26
+ Object.defineProperty(exports, "PERMISSION_DESCRIPTIONS", { enumerable: true, get: function () { return constants_1.PERMISSION_DESCRIPTIONS; } });
27
+ Object.defineProperty(exports, "RESPONSE_TYPE", { enumerable: true, get: function () { return constants_1.RESPONSE_TYPE; } });
28
+ const contentGenerator_1 = __importDefault(require("./integrations/contentGenerator"));
29
+ exports.contentGenerator = contentGenerator_1.default;
30
+ const dashboard_1 = __importDefault(require("./dashboard"));
31
+ exports.dashboard = dashboard_1.default;
32
+ const departmentTrainingPlans_1 = __importDefault(require("./departmentTrainingPlans"));
33
+ exports.departmentTraingPlans = departmentTrainingPlans_1.default;
34
+ const integration_1 = __importDefault(require("./integration"));
35
+ exports.integration = integration_1.default;
36
+ const integrationConfiguration_1 = __importDefault(require("./integrationConfiguration"));
37
+ exports.integrationConfiguration = integrationConfiguration_1.default;
38
+ const groups_1 = __importDefault(require("./groups"));
39
+ exports.groups = groups_1.default;
40
+ const learningContent_1 = __importDefault(require("./learningContent"));
41
+ exports.learningContent = learningContent_1.default;
42
+ const learningPath_1 = __importDefault(require("./learningPath"));
43
+ exports.learningPath = learningPath_1.default;
44
+ const logger_1 = __importDefault(require("./logger"));
45
+ exports.logger = logger_1.default;
46
+ const microSkillsQuizes_1 = __importDefault(require("./microSkillsQuizes"));
47
+ exports.microSkillsQuizes = microSkillsQuizes_1.default;
48
+ const quotas_1 = __importDefault(require("./quotas"));
49
+ exports.quotas = quotas_1.default;
50
+ const role_1 = __importDefault(require("./role"));
51
+ exports.role = role_1.default;
52
+ const roleTemplate_1 = __importDefault(require("./roleTemplate"));
53
+ exports.roleTemplate = roleTemplate_1.default;
54
+ const security_1 = __importDefault(require("./security"));
55
+ exports.security = security_1.default;
56
+ const skill_1 = __importDefault(require("./skill"));
57
+ exports.skill = skill_1.default;
58
+ const skillAssessments_1 = __importDefault(require("./skillAssessments"));
59
+ exports.skillAssessment = skillAssessments_1.default;
60
+ const skillAssessmentTestingSession_1 = __importDefault(require("./skillAssessmentTestingSession"));
61
+ exports.skillAssessmentTestingSession = skillAssessmentTestingSession_1.default;
62
+ const skillTemplate_1 = __importDefault(require("./skillTemplate"));
63
+ exports.skillTemplate = skillTemplate_1.default;
64
+ const talentTransfromation_1 = __importDefault(require("./talentTransfromation"));
65
+ exports.talentTransfromation = talentTransfromation_1.default;
66
+ const teams_1 = __importDefault(require("./teams"));
67
+ exports.team = teams_1.default;
68
+ const tenants_1 = __importDefault(require("./tenants"));
69
+ exports.tenant = tenants_1.default;
70
+ const trainingPlans_1 = __importDefault(require("./trainingPlans"));
71
+ exports.trainingPlan = trainingPlans_1.default;
72
+ const trainingPlansProficiencyLevels_1 = __importDefault(require("./trainingPlansProficiencyLevels"));
73
+ exports.trainingPlanProficiencyLevel = trainingPlansProficiencyLevels_1.default;
74
+ const userInformation_1 = __importDefault(require("./userInformation"));
75
+ exports.userInformation = userInformation_1.default;
76
+ const users_1 = __importDefault(require("./users"));
77
+ exports.users = users_1.default;
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setDefaultIntegration = exports.setIntegrationInformation = exports.publishIntegration = exports.getEnabledContentProviders = exports.getContentInformationByUrlFromBrowser = exports.getContentInformationByUrl = exports.getIntegrationsList = exports.getIntegrationInformationById = exports.discardIntegrationChanges = exports.deleteIntegration = exports.createIntegration = void 0;
7
+ const axiosClient_1 = require("./axiosClient");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const node_html_parser_1 = __importDefault(require("node-html-parser"));
10
+ const html2plaintext_1 = __importDefault(require("html2plaintext"));
11
+ /**
12
+ * Create integration and set information
13
+ * @param {Object} data The new integration information
14
+ * @param {String} token Authorization token
15
+ */
16
+ const createIntegration = (data, token) => {
17
+ return new Promise((resolve, reject) => {
18
+ const requestData = {
19
+ data: data,
20
+ };
21
+ let confirmationRequest = axiosClient_1.client.put("api/v1/integrations/", requestData, {
22
+ headers: { authorization: token },
23
+ });
24
+ confirmationRequest
25
+ .then((response) => {
26
+ resolve(response.data);
27
+ })
28
+ .catch((error) => {
29
+ reject(error);
30
+ });
31
+ });
32
+ };
33
+ exports.createIntegration = createIntegration;
34
+ /**
35
+ * Delete integration
36
+ * @param {String} id The id of the integration to be deleted
37
+ * @param {String} token Authorization token
38
+ */
39
+ const deleteIntegration = (id, token) => {
40
+ return new Promise((resolve, reject) => {
41
+ const request = axiosClient_1.client.delete(`api/v1/integrations/`, {
42
+ headers: { authorization: token },
43
+ data: {
44
+ id: id,
45
+ },
46
+ });
47
+ request
48
+ .then((response) => {
49
+ resolve(response.data);
50
+ })
51
+ .catch((error) => {
52
+ reject(error);
53
+ });
54
+ });
55
+ };
56
+ exports.deleteIntegration = deleteIntegration;
57
+ /**
58
+ * Discard the integration draft changes
59
+ * @param {String} id The id of the role template to be deleted
60
+ * @param {String} token Authorization token
61
+ */
62
+ const discardIntegrationChanges = (id, token) => {
63
+ return new Promise((resolve, reject) => {
64
+ const data = {};
65
+ const request = axiosClient_1.client.get(`api/v1/integrations/discard/${id}`, {
66
+ headers: { authorization: token },
67
+ data: data,
68
+ });
69
+ request
70
+ .then((response) => {
71
+ resolve(response.data);
72
+ })
73
+ .catch((error) => {
74
+ reject(error);
75
+ });
76
+ });
77
+ };
78
+ exports.discardIntegrationChanges = discardIntegrationChanges;
79
+ /**
80
+ * Get integration information
81
+ * @param {String} id The id of the integration
82
+ * @param {String} version The version of the integration to be received
83
+ * @param {String} token Authorization token
84
+ */
85
+ const getIntegrationInformationById = (id, version, token) => {
86
+ return new Promise((resolve, reject) => {
87
+ let confirmationRequest = axiosClient_1.client.get(`api/v1/integrations/${id}/${version}`, {
88
+ headers: { authorization: token },
89
+ });
90
+ confirmationRequest
91
+ .then((response) => {
92
+ resolve(response.data);
93
+ })
94
+ .catch((error) => {
95
+ reject(error);
96
+ });
97
+ });
98
+ };
99
+ exports.getIntegrationInformationById = getIntegrationInformationById;
100
+ /**
101
+ * Get integrations list
102
+ * @param {Array<String>} filter The filter used to select the integration
103
+ * @param {String} type The type of the integration
104
+ * @param {String} version The version to be retrieved
105
+ * @param {Boolean} includeSupportedCapabilities If true, the supported capabilities will be included in the response
106
+ * @param {String} token Authorization token
107
+ */
108
+ const getIntegrationsList = (filter, type, version, includeSupportedCapabilities, token) => {
109
+ return new Promise((resolve, reject) => {
110
+ const requestData = {
111
+ includeSupportedCapabilities: includeSupportedCapabilities,
112
+ version: version,
113
+ };
114
+ if (filter)
115
+ requestData.filter = filter;
116
+ if (type)
117
+ requestData.type = type;
118
+ let confirmationRequest = axiosClient_1.client.post(`api/v1/integrations`, requestData, {
119
+ headers: { authorization: token },
120
+ });
121
+ confirmationRequest
122
+ .then((response) => {
123
+ resolve(response.data);
124
+ })
125
+ .catch((error) => {
126
+ reject(error);
127
+ });
128
+ });
129
+ };
130
+ exports.getIntegrationsList = getIntegrationsList;
131
+ /**
132
+ * Get content information by Url
133
+ * @param {String} url The training url
134
+ * @param {String} verb The verb
135
+ * @param {String} token Authorization token
136
+ */
137
+ const getContentInformationByUrl = (url, verb, token) => {
138
+ return new Promise((resolve, reject) => {
139
+ const requestData = {
140
+ url: url,
141
+ verb: verb,
142
+ };
143
+ let confirmationRequest = axiosClient_1.client.post(`api/v1/contentproviders/getcontentinformationbyurl`, requestData, {
144
+ headers: { authorization: token },
145
+ });
146
+ confirmationRequest
147
+ .then((response) => {
148
+ resolve(response.data);
149
+ })
150
+ .catch((error) => {
151
+ reject(error);
152
+ });
153
+ });
154
+ };
155
+ exports.getContentInformationByUrl = getContentInformationByUrl;
156
+ /**
157
+ * Get content information by url from the browser instead of the backend
158
+ * @param {String} url
159
+ * @returns {Promise<ContentInformationResponse>}
160
+ */
161
+ const getContentInformationByUrlFromBrowser = (url) => {
162
+ return new Promise((resolve, reject) => {
163
+ let domain = new URL(url);
164
+ let instance = axios_1.default.create({
165
+ baseURL: domain.origin,
166
+ });
167
+ let confirmationRequest = instance.get(domain.pathname, {
168
+ headers: {
169
+ "Access-Control-Allow-Origin": "*",
170
+ "Access-Control-Allow-Headers": "Authorization, Origin, X-Requested-With, Content-Type, Accept",
171
+ Accept: "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",
172
+ "Accept-Encoding": "gzip, deflate, br",
173
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
174
+ "User-Agent": "Mozilla/5.0",
175
+ },
176
+ });
177
+ confirmationRequest
178
+ .then((response) => {
179
+ //get the reading time
180
+ const getReadingTime = (text) => {
181
+ const wpm = 225;
182
+ const words = text.trim().split(/\s+/).length;
183
+ return Math.ceil(words / wpm);
184
+ };
185
+ let document = node_html_parser_1.default.parse(response.data);
186
+ let duration = getReadingTime((0, html2plaintext_1.default)(response.data));
187
+ let titleTag = document.querySelector("title");
188
+ let title = titleTag ? titleTag.rawText : "";
189
+ let description = "";
190
+ const descriptionEl = document.querySelector("meta");
191
+ try {
192
+ if (descriptionEl) {
193
+ const descriptionParentNode = descriptionEl.parentNode;
194
+ if (descriptionParentNode) {
195
+ const descriptionChildNodes = descriptionParentNode.childNodes;
196
+ if (descriptionChildNodes) {
197
+ const descriptionRawAttr = descriptionChildNodes.find((item) => item.rawAttrs.includes("description"));
198
+ if (descriptionRawAttr) {
199
+ const descriptionContent = descriptionRawAttr.rawAttrs.substring(descriptionRawAttr.rawAttrs.indexOf("content=") + 9);
200
+ description = descriptionContent.substring(0, descriptionContent.length - 1);
201
+ }
202
+ }
203
+ }
204
+ }
205
+ }
206
+ finally {
207
+ resolve({
208
+ description: description,
209
+ duration: duration,
210
+ icon: `http://www.google.com/s2/favicons?sz=128&domain_url=${domain.hostname}`,
211
+ title: title ? title.trim() : url,
212
+ type: 0,
213
+ internal: true,
214
+ });
215
+ }
216
+ })
217
+ .catch((error) => {
218
+ reject(new Error((0, axiosClient_1.errorToString)(error)));
219
+ });
220
+ });
221
+ };
222
+ exports.getContentInformationByUrlFromBrowser = getContentInformationByUrlFromBrowser;
223
+ /**
224
+ * Get enabled content providers
225
+ * @param {String} userId
226
+ * @param {String} token Authorization token
227
+ */
228
+ const getEnabledContentProviders = (userId, token) => {
229
+ return new Promise((resolve, reject) => {
230
+ let confirmationRequest = axiosClient_1.client.get(`api/v1/contentproviders/getenabledcontentproviders/${userId}`, {
231
+ headers: { authorization: token },
232
+ });
233
+ confirmationRequest
234
+ .then((response) => {
235
+ resolve(response.data);
236
+ })
237
+ .catch((error) => {
238
+ reject(error);
239
+ });
240
+ });
241
+ };
242
+ exports.getEnabledContentProviders = getEnabledContentProviders;
243
+ /**
244
+ * Publish integration
245
+ * @param {String} id The id of the integration to be published
246
+ * @param {String} token Authorization token
247
+ */
248
+ const publishIntegration = (id, token) => {
249
+ return new Promise((resolve, reject) => {
250
+ let confirmationRequest = axiosClient_1.client.post(`api/v1/integrations/publish/${id}`, {}, {
251
+ headers: { authorization: token },
252
+ });
253
+ confirmationRequest
254
+ .then((response) => {
255
+ resolve(response.data);
256
+ })
257
+ .catch((error) => {
258
+ reject(error);
259
+ });
260
+ });
261
+ };
262
+ exports.publishIntegration = publishIntegration;
263
+ /**
264
+ * Set integration information
265
+ * @param {String} id The id of the integration to be updated
266
+ * @param {Object} data Data used to update the integration
267
+ * @param {String} token Authorization token
268
+ */
269
+ const setIntegrationInformation = (id, data, token) => {
270
+ return new Promise((resolve, reject) => {
271
+ const requestData = {
272
+ data: data,
273
+ };
274
+ let confirmationRequest = axiosClient_1.client.post(`api/v1/integrations/${id}`, requestData, {
275
+ headers: { authorization: token },
276
+ });
277
+ confirmationRequest
278
+ .then((response) => {
279
+ resolve(response.data);
280
+ })
281
+ .catch((error) => {
282
+ reject(error);
283
+ });
284
+ });
285
+ };
286
+ exports.setIntegrationInformation = setIntegrationInformation;
287
+ /**
288
+ * Set default integration
289
+ * @param {String} id The id of the integration to be set as default
290
+ * @param {String} token Authorization token
291
+ */
292
+ const setDefaultIntegration = (id, token) => {
293
+ return new Promise((resolve, reject) => {
294
+ let confirmationRequest = axiosClient_1.client.post(`api/v1/integrations/${id}/default`, "", {
295
+ headers: { authorization: token },
296
+ });
297
+ confirmationRequest
298
+ .then((response) => {
299
+ resolve(response.data);
300
+ })
301
+ .catch((error) => {
302
+ reject(error);
303
+ });
304
+ });
305
+ };
306
+ exports.setDefaultIntegration = setDefaultIntegration;
307
+ exports.default = {
308
+ createIntegration: exports.createIntegration,
309
+ deleteIntegration: exports.deleteIntegration,
310
+ discardIntegrationChanges: exports.discardIntegrationChanges,
311
+ getContentInformationByUrl: exports.getContentInformationByUrl,
312
+ getContentInformationByUrlFromBrowser: exports.getContentInformationByUrlFromBrowser,
313
+ getEnabledContentProviders: exports.getEnabledContentProviders,
314
+ getIntegrationInformationById: exports.getIntegrationInformationById,
315
+ getIntegrationsList: exports.getIntegrationsList,
316
+ publishIntegration: exports.publishIntegration,
317
+ setDefaultIntegration: exports.setDefaultIntegration,
318
+ setIntegrationInformation: exports.setIntegrationInformation,
319
+ };