@meltwater/conversations-api-services 1.0.19 → 1.0.21

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 (70) hide show
  1. package/.github/workflows/release.yml +2 -0
  2. package/babel.config.js +18 -0
  3. package/dist/cjs/data-access/http/InstagramVideoClient.js +42 -0
  4. package/dist/cjs/data-access/http/WarpZoneApi.client.js +32 -0
  5. package/dist/cjs/data-access/http/amazonS3.js +44 -0
  6. package/dist/cjs/data-access/http/asset-manager-tvm.client.js +35 -0
  7. package/dist/cjs/data-access/http/companiesApi.client.js +38 -0
  8. package/dist/cjs/data-access/http/credentialsApi.client.js +102 -0
  9. package/dist/cjs/data-access/http/entitlementsApi.client.js +40 -0
  10. package/dist/cjs/data-access/http/facebook.native.js +344 -0
  11. package/dist/cjs/data-access/http/facebookApi.client.js +631 -0
  12. package/dist/cjs/data-access/http/featureToggleApi.client.js +31 -0
  13. package/dist/cjs/data-access/http/identityServices.client.js +97 -0
  14. package/dist/cjs/data-access/http/instagramApi.client.js +428 -0
  15. package/dist/cjs/data-access/http/ir.client.js +242 -0
  16. package/dist/cjs/data-access/http/linkedInApi.client.js +491 -0
  17. package/dist/cjs/data-access/http/masf.client.js +101 -0
  18. package/dist/cjs/data-access/http/tiktok.native.js +162 -0
  19. package/dist/cjs/data-access/http/tiktokApi.client.js +441 -0
  20. package/dist/cjs/data-access/index.js +132 -0
  21. package/dist/cjs/errors/engage-error.js +16 -0
  22. package/dist/cjs/errors/http-error.js +23 -0
  23. package/dist/cjs/lib/applicationTags.helpers.js +30 -0
  24. package/dist/cjs/lib/configuration.js +14 -0
  25. package/dist/cjs/lib/document-action-events.js +12 -0
  26. package/dist/cjs/lib/externalId.helpers.js +19 -0
  27. package/dist/cjs/lib/hidden.helpers.js +13 -0
  28. package/dist/cjs/lib/hiddenComment.helper.js +119 -0
  29. package/dist/cjs/lib/logger.helpers.js +68 -0
  30. package/dist/cjs/lib/logger.js +23 -0
  31. package/dist/cjs/lib/message.helpers.js +58 -0
  32. package/dist/cjs/lib/metrics.helper.js +97 -0
  33. package/dist/esm/data-access/http/InstagramVideoClient.js +34 -0
  34. package/dist/esm/data-access/http/WarpZoneApi.client.js +24 -0
  35. package/dist/esm/data-access/http/amazonS3.js +37 -0
  36. package/dist/esm/data-access/http/asset-manager-tvm.client.js +28 -0
  37. package/dist/esm/data-access/http/companiesApi.client.js +30 -0
  38. package/dist/esm/data-access/http/credentialsApi.client.js +92 -0
  39. package/dist/esm/data-access/http/entitlementsApi.client.js +32 -0
  40. package/dist/esm/data-access/http/facebook.native.js +325 -0
  41. package/dist/esm/data-access/http/facebookApi.client.js +621 -0
  42. package/dist/esm/data-access/http/featureToggleApi.client.js +23 -0
  43. package/dist/esm/data-access/http/identityServices.client.js +89 -0
  44. package/dist/esm/data-access/http/instagramApi.client.js +420 -0
  45. package/dist/esm/data-access/http/ir.client.js +234 -0
  46. package/dist/esm/data-access/http/linkedInApi.client.js +481 -0
  47. package/dist/esm/data-access/http/masf.client.js +93 -0
  48. package/dist/esm/data-access/http/tiktok.native.js +146 -0
  49. package/dist/esm/data-access/http/tiktokApi.client.js +433 -0
  50. package/dist/esm/data-access/index.js +30 -0
  51. package/dist/esm/errors/engage-error.js +9 -0
  52. package/dist/esm/errors/http-error.js +16 -0
  53. package/dist/esm/lib/applicationTags.helpers.js +22 -0
  54. package/dist/esm/lib/configuration.js +8 -0
  55. package/dist/esm/lib/document-action-events.js +6 -0
  56. package/dist/esm/lib/externalId.helpers.js +12 -0
  57. package/dist/esm/lib/hidden.helpers.js +6 -0
  58. package/dist/esm/lib/hiddenComment.helper.js +112 -0
  59. package/dist/esm/lib/logger.helpers.js +60 -0
  60. package/dist/esm/lib/logger.js +16 -0
  61. package/dist/esm/lib/message.helpers.js +52 -0
  62. package/dist/esm/lib/metrics.helper.js +90 -0
  63. package/package.json +14 -4
  64. package/src/data-access/http/facebook.native.js +542 -0
  65. package/src/data-access/http/tiktok.native.js +248 -0
  66. package/src/data-access/index.js +4 -0
  67. package/src/errors/engage-error.js +11 -0
  68. package/src/errors/http-error.js +19 -0
  69. package/src/lib/logger.helpers.js +15 -0
  70. package/src/lib/message.helpers.js +7 -1
@@ -0,0 +1,481 @@
1
+ import superagent from 'superagent';
2
+ import configuration from '../../lib/configuration.js';
3
+ import { CredentialsApiClient } from '../http/credentialsApi.client.js';
4
+ import logger from '../../lib/logger.js';
5
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
6
+ export class LinkedInApiClient {
7
+ constructor() {
8
+ this.credentialsAPI = new CredentialsApiClient();
9
+ }
10
+ async likeMessage(document) {
11
+ const {
12
+ documentId,
13
+ systemData: {
14
+ connectionsCredential: credentialId,
15
+ policies: {
16
+ storage: {
17
+ privateTo: companyId
18
+ }
19
+ }
20
+ },
21
+ metaData: {
22
+ externalId,
23
+ source: {
24
+ id: socialAccountId
25
+ }
26
+ },
27
+ enrichments: {
28
+ socialScores: {
29
+ li_liked_by_user: likedByUser
30
+ }
31
+ }
32
+ } = document;
33
+ const loggerChild = logger.child({
34
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
35
+ [MeltwaterAttributes.COMPANYID]: companyId,
36
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
37
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId
38
+ });
39
+ let response;
40
+ let payload = {
41
+ actor: socialAccountId,
42
+ object: externalId
43
+ };
44
+ let query = likedByUser ? `${configuration.get('LINKEDIN_API')}/socialActions/${fixedEncodeURIComponent(externalId)}/likes` : `${configuration.get('LINKEDIN_API')}/socialActions/${fixedEncodeURIComponent(externalId)}/likes/${fixedEncodeURIComponent(payload.actor)}?actor=${fixedEncodeURIComponent(payload.actor)}`;
45
+ try {
46
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
47
+ if (!likedByUser) {
48
+ loggerChild.debug(`${documentId} - trying Delete `, {
49
+ query,
50
+ payload: JSON.stringify(payload)
51
+ });
52
+ response = await superagent.delete(query).timeout(5000).set({
53
+ Authorization: `Bearer ${credential.token}`,
54
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
55
+ 'LinkedIn-Version': '202311'
56
+ });
57
+ } else {
58
+ loggerChild.debug(`${documentId} - sending to linkedin `, {
59
+ query,
60
+ payload: JSON.stringify(payload)
61
+ });
62
+ response = await superagent.post(query).timeout(5000) // 5 seconds
63
+ .set({
64
+ Authorization: `Bearer ${credential.token}`,
65
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
66
+ 'LinkedIn-Version': '202311'
67
+ }).send(payload);
68
+ }
69
+ loggerChild.info(`Native Linkedin API Like Comment Response for documentId ${documentId}`, {
70
+ ok: response.ok,
71
+ status: response.status,
72
+ message: JSON.parse(response.text),
73
+ likedByUser
74
+ });
75
+ } catch (err) {
76
+ loggerChild.error(`${documentId} - exception details`, err);
77
+ throw err;
78
+ }
79
+ return response.connection || response;
80
+ }
81
+ async deleteMessage(document) {
82
+ const {
83
+ documentId,
84
+ systemData: {
85
+ connectionsCredential: credentialId,
86
+ policies: {
87
+ storage: {
88
+ privateTo: companyId
89
+ }
90
+ }
91
+ },
92
+ metaData: {
93
+ externalId,
94
+ source: {
95
+ id: actorURN
96
+ },
97
+ inReplyTo: {
98
+ id: inReplyToId
99
+ }
100
+ }
101
+ } = document;
102
+ const loggerChild = logger.child({
103
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
104
+ [MeltwaterAttributes.COMPANYID]: companyId,
105
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
106
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId
107
+ });
108
+ const [, comment] = externalId.split(',');
109
+ const commentId = comment.split(')')[0];
110
+ let response;
111
+ let query = `${configuration.get('LINKEDIN_API')}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments/${commentId}?actor=${fixedEncodeURIComponent(actorURN)}`;
112
+ try {
113
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
114
+ loggerChild.debug(`${documentId} - trying Delete `, {
115
+ query
116
+ });
117
+ response = await superagent.delete(query).timeout(5000).set({
118
+ Authorization: `Bearer ${credential.token}`,
119
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
120
+ 'LinkedIn-Version': '202311'
121
+ });
122
+ loggerChild.info(`Native Linkedin API Delete Comment Response for documentId ${documentId}`, {
123
+ status: response.status,
124
+ ok: response.ok
125
+ });
126
+ } catch (err) {
127
+ let errorText = '';
128
+ if (err && err.response && err.response.text) {
129
+ errorText = `Call to linkedin api with documentId ${documentId} failed`;
130
+ loggerChild.error(errorText, {
131
+ message: JSON.parse(err.response.text)
132
+ });
133
+ } else {
134
+ errorText = `Call to linkedin api with documentId ${documentId} failed`;
135
+ loggerChild.error(errorText, err);
136
+ }
137
+ throw new Error(errorText);
138
+ }
139
+ return response;
140
+ }
141
+ async publishComment(document, mediaId) {
142
+ // command
143
+ const {
144
+ documentId,
145
+ systemData: {
146
+ connectionsCredential: credentialId,
147
+ policies: {
148
+ storage: {
149
+ privateTo: companyId
150
+ }
151
+ }
152
+ },
153
+ body: {
154
+ content: {
155
+ text: messageText
156
+ }
157
+ },
158
+ metaData: {
159
+ discussionType,
160
+ inReplyTo: {
161
+ id: parentUrn
162
+ },
163
+ source: {
164
+ id: socialAccountId
165
+ }
166
+ }
167
+ } = document;
168
+ let messageType = discussionType === 're' ? 'reply' : 'comment';
169
+
170
+ // for now this is needed to make the urns from the images api work until the docs are updated to reflect how to use these new ids.
171
+ if (mediaId) {
172
+ mediaId = mediaId.replace('urn:li:image:', 'urn:li:digitalmediaAsset:');
173
+ }
174
+ let body = {
175
+ actor: socialAccountId,
176
+ message: {
177
+ attributes: [],
178
+ text: messageText
179
+ }
180
+ };
181
+ if (messageType === 'reply') {
182
+ body.parentComment = parentUrn;
183
+ }
184
+ if (mediaId) {
185
+ body.content = [{
186
+ entity: {
187
+ digitalmediaAsset: mediaId
188
+ },
189
+ type: 'IMAGE'
190
+ }];
191
+ }
192
+ let query = `${configuration.get('LINKEDIN_API')}/socialActions/${fixedEncodeURIComponent(parentUrn)}/comments`;
193
+
194
+ // data-listener -> linkedin_api.client sendComment
195
+ let response, updatedDocument;
196
+ try {
197
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
198
+ let response = await superagent.post(query).timeout(5000).set({
199
+ Authorization: `Bearer ${credential.token}`,
200
+ 'Content-Type': 'application/json',
201
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
202
+ 'LinkedIn-Version': '202311'
203
+ }).send(body);
204
+ response = {
205
+ status: 200,
206
+ message: JSON.parse(response.text)
207
+ };
208
+ } catch (err) {
209
+ logger.error(`${documentId} - exception linkedin publish`, err, {
210
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
211
+ [MeltwaterAttributes.COMPANYID]: companyId,
212
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
213
+ });
214
+ }
215
+ return response;
216
+ }
217
+ async getMediaUploadURL(companyId, credentialId, socialAccountId, documentId) {
218
+ let query = `${configuration.get('LINKEDIN_API')}/images?action=initializeUpload`;
219
+ let body = {
220
+ initializeUploadRequest: {
221
+ owner: socialAccountId
222
+ }
223
+ };
224
+ let response;
225
+ try {
226
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
227
+ response = await superagent.post(query).timeout(5000).set({
228
+ Authorization: `Bearer ${credential.token}`,
229
+ 'Content-type': 'application/json',
230
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
231
+ 'LinkedIn-Version': '202311'
232
+ }).send(body);
233
+ response = {
234
+ status: 200,
235
+ message: JSON.parse(response.text)
236
+ };
237
+ return response;
238
+ } catch (err) {
239
+ logger.error(`${documentId} - exception linkedin media register`, err, {
240
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
241
+ [MeltwaterAttributes.COMPANYID]: companyId,
242
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
243
+ });
244
+ }
245
+ }
246
+ async getAllStats(externalId, token) {
247
+ let response = {};
248
+ const loggerChild = logger.child({
249
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId
250
+ });
251
+ try {
252
+ response = await superagent.get(configuration.get('LINKEDIN_API') + '/socialMetadata/' + fixedEncodeURIComponent(externalId)).timeout(5000) // 5 seconds
253
+ .set({
254
+ Authorization: `Bearer ${token}`,
255
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
256
+ 'LinkedIn-Version': '202311'
257
+ });
258
+ } catch (error) {
259
+ loggerChild.error('Error in getAllStats', error);
260
+ }
261
+ let {
262
+ commentSummary,
263
+ reactionSummaries
264
+ } = response.body || {};
265
+ if (commentSummary && reactionSummaries) {
266
+ return {
267
+ commentSummary,
268
+ reactionSummaries
269
+ };
270
+ } else {
271
+ loggerChild.error(`Invalid response getting all Linkedin Stats for externalId = ${externalId}`, {
272
+ response: JSON.stringify(response)
273
+ });
274
+ return {};
275
+ }
276
+ }
277
+ async getSocialStats(externalId, token) {
278
+ try {
279
+ // get all stats (likes are not to be trusted) seems to only work
280
+ // for og posts.
281
+ const {
282
+ commentSummary,
283
+ reactionSummaries
284
+ } = await this.getAllStats(externalId, token);
285
+ return {
286
+ commentSummary,
287
+ reactionSummaries
288
+ };
289
+ } catch (error) {
290
+ logger.error('Error in getSocialStats', error, {
291
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId
292
+ });
293
+ }
294
+ }
295
+ async getImageMedia(mediaId, credentialId, companyId) {
296
+ let response = {};
297
+ const loggerChild = logger.child({
298
+ [MeltwaterAttributes.COMPANYID]: companyId,
299
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
300
+ });
301
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
302
+ if (mediaId && mediaId.includes('digitalmediaAsset')) {
303
+ mediaId = mediaId.replace('urn:li:digitalmediaAsset:', 'urn:li:image:');
304
+ }
305
+ try {
306
+ response = await superagent.get(configuration.get('LINKEDIN_API') + '/images/' + fixedEncodeURIComponent(mediaId)).timeout(5000) // 5 seconds
307
+ .set({
308
+ Authorization: `Bearer ${credential.token}`,
309
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
310
+ 'LinkedIn-Version': '202311'
311
+ });
312
+ } catch (error) {
313
+ loggerChild.error('Error in getImageMedia', error);
314
+ }
315
+ let {
316
+ downloadUrl
317
+ } = response.body || {};
318
+ if (downloadUrl) {
319
+ return {
320
+ downloadUrl
321
+ };
322
+ } else {
323
+ loggerChild.error(`Invalid response getting Linkedin media for mediaId: ${mediaId}`, {
324
+ response: JSON.stringify(response)
325
+ });
326
+ return {};
327
+ }
328
+ }
329
+ async getVideoMedia(mediaId, credentialId, companyId) {
330
+ let response = {};
331
+ let tempValue;
332
+ const loggerChild = logger.child({
333
+ [MeltwaterAttributes.COMPANYID]: companyId,
334
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
335
+ });
336
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
337
+ if (mediaId && mediaId.includes('digitalmediaMediaArtifact')) {
338
+ tempValue = mediaId.split('digitalmediaMediaArtifact:(')[1];
339
+ tempValue = tempValue.split(',urn:li:digitalmediaMediaArtifactClass')[0];
340
+ mediaId = tempValue;
341
+ }
342
+ if (mediaId && mediaId.includes('digitalmediaAsset')) {
343
+ mediaId = mediaId.replace('urn:li:digitalmediaAsset:', 'urn:li:video:');
344
+ }
345
+ try {
346
+ response = await superagent.get(configuration.get('LINKEDIN_API') + '/videos/' + fixedEncodeURIComponent(mediaId)).timeout(5000) // 5 seconds
347
+ .set({
348
+ Authorization: `Bearer ${credential.token}`,
349
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
350
+ 'LinkedIn-Version': '202311'
351
+ });
352
+ } catch (error) {
353
+ loggerChild.error('Error in getVideoMedia', error);
354
+ }
355
+ let {
356
+ thumbnail,
357
+ downloadUrl
358
+ } = response.body || {};
359
+ if (downloadUrl) {
360
+ return {
361
+ thumbnail,
362
+ downloadUrl
363
+ };
364
+ } else {
365
+ loggerChild.error(`Invalid response getting Linkedin media for mediaId: ${mediaId}`, {
366
+ response: JSON.stringify(response)
367
+ });
368
+ return {};
369
+ }
370
+ }
371
+ async getMedia(mediaId, type, credentialId, companyId) {
372
+ // needed due to issue with polled data
373
+ if (type.includes('video') && mediaId.includes('image')) {
374
+ type = 'image/jpeg';
375
+ }
376
+ try {
377
+ if (type.includes('image')) {
378
+ const {
379
+ downloadUrl
380
+ } = await this.getImageMedia(mediaId, credentialId, companyId);
381
+ return {
382
+ downloadUrl
383
+ };
384
+ } else if (type.includes('video')) {
385
+ const {
386
+ thumbnail,
387
+ downloadUrl
388
+ } = await this.getVideoMedia(mediaId, credentialId, companyId);
389
+ return {
390
+ thumbnail,
391
+ downloadUrl
392
+ };
393
+ }
394
+ return {};
395
+ } catch (error) {
396
+ logger.error('Error in getMedia', error, {
397
+ [MeltwaterAttributes.COMPANYID]: companyId,
398
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
399
+ });
400
+ }
401
+ }
402
+ async getLikedByUser(externalId, authorExternalId, credentialId, companyId) {
403
+ let result;
404
+ try {
405
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
406
+ result = await superagent.get(`${configuration.get('LINKEDIN_API')}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
407
+ Authorization: `Bearer ${credential.token}`,
408
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
409
+ 'LinkedIn-Version': '202311'
410
+ }).then(result => result.body);
411
+ } catch (error) {
412
+ logger.error('Error in getLikesByUser', error, {
413
+ [MeltwaterAttributes.COMPANYID]: companyId,
414
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId,
415
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
416
+ });
417
+ return false;
418
+ }
419
+ return true;
420
+ }
421
+ async uploadMedia(query) {
422
+ const {
423
+ socialAccountId,
424
+ url,
425
+ token,
426
+ data
427
+ } = query;
428
+ logger.info(`Starting to upload media to linkedin for ${socialAccountId}`, {
429
+ url: query.url
430
+ });
431
+ return await superagent.put(url).set({
432
+ Accept: '*/*',
433
+ 'Content-Type': 'application/octet-stream',
434
+ Authorization: `Bearer ${token}`,
435
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
436
+ 'LinkedIn-Version': '202311'
437
+ }).send(data).catch(err => {
438
+ logger.error(err);
439
+ throw err;
440
+ });
441
+ }
442
+ }
443
+ export async function getProfile(urn, token) {
444
+ let [,,, id] = urn.split(':');
445
+ let profile;
446
+ try {
447
+ profile = await superagent.get(`${configuration.get('LINKEDIN_API')}/people/(id:${id})`).query({
448
+ projection: '(id,localizedFirstName,localizedLastName,vanityName,profilePicture(displayImage~:playableStreams))'
449
+ }).timeout(5000).set({
450
+ Authorization: `Bearer ${token}`,
451
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
452
+ 'LinkedIn-Version': '202311'
453
+ }).then(result => result.body);
454
+ } catch (error) {
455
+ logger.error(`Failed requesting LinkedIn API for profileId ${urn}`, error);
456
+ return;
457
+ }
458
+ logger.info(`Finished requesting LinkedIn API for profileId ${urn}`);
459
+ return profile;
460
+ }
461
+ export async function getOrganization(urn, token) {
462
+ let [,,, id] = urn.split(':');
463
+ let organization;
464
+ try {
465
+ organization = await superagent.get(`${configuration.get('LINKEDIN_API')}/organizations/${id}`).query({
466
+ projection: '(id,localizedName,vanityName,logoV2(original~:playableStreams))'
467
+ }).timeout(5000) // 5 seconds
468
+ .set({
469
+ Authorization: `Bearer ${token}`,
470
+ 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
471
+ 'LinkedIn-Version': '202311'
472
+ }).then(result => result.body);
473
+ } catch (error) {
474
+ logger.error(`Failed requesting LinkedIn API for organizationId ${urn}`, error);
475
+ }
476
+ logger.info(`Finished requesting LinkedIn API for organizationId ${urn}`);
477
+ return organization;
478
+ }
479
+ function fixedEncodeURIComponent(str) {
480
+ return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
481
+ }
@@ -0,0 +1,93 @@
1
+ import superagent from 'superagent';
2
+ import logger from '../../lib/logger.js';
3
+ import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
5
+ export class MasfClient {
6
+ constructor() {
7
+ this.searchServicesUrlMasf = configuration.get('MASF_SEARCH_SERVICE_URL');
8
+ this.searchServicesVersionMasf = configuration.get('MASF_SEARCH_SERVICE_VERSION');
9
+ this.xClientName = configuration.get('CLIENT_NAME_HEADER');
10
+ this.authorListVersionMasf = 'v3';
11
+ }
12
+ async getSearches(_ref) {
13
+ let {
14
+ companyId,
15
+ token
16
+ } = _ref;
17
+ try {
18
+ let uri = `${this.searchServicesUrlMasf}/${this.searchServicesVersionMasf}/company/${companyId}/searches`;
19
+ return (await superagent.get(uri).set({
20
+ Authorization: `${token}`
21
+ })).body;
22
+ } catch (error) {
23
+ logger.error(`Failed requesting Search Services for search list `, error, {
24
+ [MeltwaterAttributes.COMPANYID]: companyId
25
+ });
26
+ }
27
+ }
28
+ async getAuthorsLists(_ref2) {
29
+ let {
30
+ companyId,
31
+ token
32
+ } = _ref2;
33
+ try {
34
+ let uri = `${this.searchServicesUrlMasf}/v3/companies/${companyId}/authorlists`;
35
+ return (await superagent.get(uri).set({
36
+ Authorization: `${token}`
37
+ }).set('x-client-name', this.xClientName)).body.sort((_ref3, _ref4) => {
38
+ let {
39
+ name: n1
40
+ } = _ref3;
41
+ let {
42
+ name: n2
43
+ } = _ref4;
44
+ if (n1.toUpperCase() < n2.toUpperCase()) {
45
+ return -1;
46
+ }
47
+ if (n1.toUpperCase() > n2.toUpperCase()) {
48
+ return 1;
49
+ }
50
+ return 0;
51
+ });
52
+ } catch (error) {
53
+ logger.error(`Failed requesting Search Services for author list `, error, {
54
+ [MeltwaterAttributes.COMPANYID]: companyId
55
+ });
56
+ }
57
+ }
58
+ async getAuthorsList(_ref5) {
59
+ let {
60
+ companyId,
61
+ authorListId,
62
+ token
63
+ } = _ref5;
64
+ try {
65
+ let uri = `${this.searchServicesUrlMasf}/${this.authorListVersionMasf}/companies/${companyId}/authorlists/${authorListId}`;
66
+ return (await superagent.get(uri).set({
67
+ Authorization: `${token}`
68
+ })).body;
69
+ } catch (error) {
70
+ logger.error(`Failed requesting Search Services for author list `, error, {
71
+ [MeltwaterAttributes.COMPANYID]: companyId
72
+ });
73
+ }
74
+ }
75
+ async getRune(_ref6) {
76
+ let {
77
+ searchId,
78
+ token
79
+ } = _ref6;
80
+ let rune;
81
+ try {
82
+ let uri = `${this.searchServicesUrlMasf}/${this.searchServicesVersionMasf}/search/getSavedSearchAsRunes/${searchId}`;
83
+ rune = await superagent.get(uri).set({
84
+ Authorization: `${token}`
85
+ });
86
+ } catch (error) {
87
+ logger.error(`Failed requesting Search Services for search list `, error);
88
+ return;
89
+ }
90
+ logger.info(`Finished requesting Search Services for rune ${this.searchServicesUrlMasf} searchId: ${searchId}`);
91
+ return rune.body;
92
+ }
93
+ }