@meltwater/conversations-api-services 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.
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getURL = getURL;
7
7
  var _loggerHelpers = require("../../lib/logger.helpers.js");
8
+ var _superagent = _interopRequireDefault(require("superagent"));
8
9
  var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const superagent = require('superagent');
11
11
  const gatewayURL = _configuration.default.get('ASSETMANAGER_GATEWAY_URL');
12
12
  async function getURL(jwt, assetId, logger) {
13
13
  try {
14
- const response = await superagent.post(`${gatewayURL}`).set('apollographql-client-name', 'phoenix-conversations').set('Authorization', jwt).send({
14
+ const response = await _superagent.default.post(`${gatewayURL}`).set('apollographql-client-name', 'phoenix-conversations').set('Authorization', jwt).send({
15
15
  query: `
16
16
  query getAssetUrlForPublishing(
17
17
  $filter: AssetFilterInput
@@ -12,6 +12,7 @@ var _configuration = _interopRequireDefault(require("../../lib/configuration.js"
12
12
  var _credentialsApiClient = require("../http/credentialsApi.client.js");
13
13
  var _logger = _interopRequireDefault(require("../../lib/logger.js"));
14
14
  var _loggerHelpers = require("../../lib/logger.helpers.js");
15
+ var _linkedinNative = require("./linkedin.native.js");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  class LinkedInApiClient {
17
18
  constructor() {
@@ -119,34 +120,8 @@ class LinkedInApiClient {
119
120
  const commentId = comment.split(')')[0];
120
121
  let response;
121
122
  let query = `${_configuration.default.get('LINKEDIN_API')}/socialActions/${fixedEncodeURIComponent(inReplyToId)}/comments/${commentId}?actor=${fixedEncodeURIComponent(actorURN)}`;
122
- try {
123
- let credential = await this.credentialsAPI.getToken(credentialId, companyId);
124
- loggerChild.debug(`${documentId} - trying Delete `, {
125
- query
126
- });
127
- response = await _superagent.default.delete(query).timeout(5000).set({
128
- Authorization: `Bearer ${credential.token}`,
129
- 'X-RestLi-Protocol-Version': _configuration.default.get('LINKEDIN_API_VERSION'),
130
- 'LinkedIn-Version': '202311'
131
- });
132
- loggerChild.info(`Native Linkedin API Delete Comment Response for documentId ${documentId}`, {
133
- status: response.status,
134
- ok: response.ok
135
- });
136
- } catch (err) {
137
- let errorText = '';
138
- if (err && err.response && err.response.text) {
139
- errorText = `Call to linkedin api with documentId ${documentId} failed`;
140
- loggerChild.error(errorText, {
141
- message: JSON.parse(err.response.text)
142
- });
143
- } else {
144
- errorText = `Call to linkedin api with documentId ${documentId} failed`;
145
- loggerChild.error(errorText, err);
146
- }
147
- throw new Error(errorText);
148
- }
149
- return response;
123
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
124
+ return (0, _linkedinNative.deleteMessage)(credential.token, externalId, actorURN, inReplyToId, loggerChild);
150
125
  }
151
126
  async publishComment(document, mediaId) {
152
127
  // command
@@ -470,41 +445,10 @@ async function getProfile(urn, token) {
470
445
  return profile;
471
446
  }
472
447
  async function getOrganization(urn, token) {
473
- let [,,, id] = urn.split(':');
474
- let organization;
475
- try {
476
- organization = await _superagent.default.get(`${_configuration.default.get('LINKEDIN_API')}/organizations/${id}`).query({
477
- projection: '(id,localizedName,vanityName,logoV2(original~:playableStreams))'
478
- }).timeout(5000) // 5 seconds
479
- .set({
480
- Authorization: `Bearer ${token}`,
481
- 'X-RestLi-Protocol-Version': _configuration.default.get('LINKEDIN_API_VERSION'),
482
- 'LinkedIn-Version': '202311'
483
- }).then(result => result.body);
484
- } catch (error) {
485
- _logger.default.error(`Failed requesting LinkedIn API for organizationId ${urn}`, error);
486
- }
487
- _logger.default.info(`Finished requesting LinkedIn API for organizationId ${urn}`);
488
- return organization;
448
+ return (0, _linkedinNative.getOrganization)(urn, token, _logger.default);
489
449
  }
490
450
  async function getOrganizations(urn, token) {
491
- const [,,, id] = urn.split(':');
492
- let organizations;
493
- try {
494
- organizations = await _superagent.default.get(`${_configuration.default.get('LINKEDIN_API_DATE')}/organizationsLookup?ids=List(${id})`).timeout(5000) // 5 seconds
495
- .set({
496
- Authorization: `Bearer ${token}`,
497
- 'X-RestLi-Protocol-Version': _configuration.default.get('LINKEDIN_API_VERSION'),
498
- 'LinkedIn-Version': '202411'
499
- }).then(result => {
500
- const res = result.body;
501
- return res.results[id];
502
- });
503
- } catch (error) {
504
- _logger.default.error(`Failed requesting LinkedIn API for organization id ${id}`, error);
505
- }
506
- _logger.default.info(`Finished requesting LinkedIn API for organization id ${id}`);
507
- return organizations;
451
+ return (0, _linkedinNative.getOrganizations)(urn, token, _logger.default);
508
452
  }
509
453
  function fixedEncodeURIComponent(str) {
510
454
  return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
@@ -7,6 +7,7 @@ exports.comment = comment;
7
7
  exports.deleteMessage = deleteMessage;
8
8
  exports.getMedia = getMedia;
9
9
  exports.getOrganization = getOrganization;
10
+ exports.getOrganizations = getOrganizations;
10
11
  exports.getProfile = getProfile;
11
12
  exports.getSocialStats = getSocialStats;
12
13
  exports.getVideoMedia = getVideoMedia;
@@ -20,7 +21,9 @@ var _superagent = _interopRequireDefault(require("superagent"));
20
21
  var _loggerHelpers = require("../../lib/logger.helpers.js");
21
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
23
  const LINKEDIN_API = "https://api.linkedin.com/v2";
24
+ const LINKEDIN_API_REST = "https://api.linkedin.com/rest";
23
25
  const LINKEDIN_API_VERSION = "2.0.0";
26
+ const LINKEDIN_VERSION = "202411";
24
27
  async function like(token, externalId, socialAccountId, logger) {
25
28
  let response;
26
29
  let payload = {
@@ -37,7 +40,7 @@ async function like(token, externalId, socialAccountId, logger) {
37
40
  .set({
38
41
  Authorization: `Bearer ${token}`,
39
42
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
40
- 'LinkedIn-Version': '202311'
43
+ 'LinkedIn-Version': LINKEDIN_VERSION
41
44
  }).send(payload);
42
45
  (0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Like Mutation Response`, {
43
46
  response: JSON.stringify(response)
@@ -63,7 +66,7 @@ async function unlike(token, externalId, socialAccountId, logger) {
63
66
  response = await _superagent.default.delete(query).timeout(5000).set({
64
67
  Authorization: `Bearer ${token}`,
65
68
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
66
- 'LinkedIn-Version': '202311'
69
+ 'LinkedIn-Version': LINKEDIN_VERSION
67
70
  });
68
71
  (0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API UNLike Mutation Response`, {
69
72
  response: JSON.stringify(response)
@@ -86,7 +89,7 @@ async function deleteMessage(token, externalId, sourceId, inReplyToId, logger) {
86
89
  response = await _superagent.default.delete(query).timeout(5000).set({
87
90
  Authorization: `Bearer ${token}`,
88
91
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
89
- 'LinkedIn-Version': '202311'
92
+ 'LinkedIn-Version': LINKEDIN_VERSION
90
93
  });
91
94
  (0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Delete Comment Response`, {
92
95
  response: JSON.stringify(response)
@@ -138,7 +141,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
138
141
  Authorization: `Bearer ${token}`,
139
142
  'Content-Type': 'application/json',
140
143
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
141
- 'LinkedIn-Version': '202311'
144
+ 'LinkedIn-Version': LINKEDIN_VERSION
142
145
  }).send(body);
143
146
  (0, _loggerHelpers.loggerInfo)(logger, `Native Linkedin API Publish Comment Response`, {
144
147
  response: JSON.stringify(response)
@@ -175,7 +178,7 @@ async function getImageMedia(mediaId, token, logger) {
175
178
  .set({
176
179
  Authorization: `Bearer ${token}`,
177
180
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
178
- 'LinkedIn-Version': '202311'
181
+ 'LinkedIn-Version': LINKEDIN_VERSION
179
182
  });
180
183
  } catch (error) {
181
184
  (0, _loggerHelpers.loggerError)(logger, 'Error in getImageMedia', error);
@@ -210,7 +213,7 @@ async function getVideoMedia(mediaId, token, logger) {
210
213
  .set({
211
214
  Authorization: `Bearer ${token}`,
212
215
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
213
- 'LinkedIn-Version': '202311'
216
+ 'LinkedIn-Version': LINKEDIN_VERSION
214
217
  });
215
218
  } catch (error) {
216
219
  (0, _loggerHelpers.loggerError)(logger, 'Error in getVideoMedia', error);
@@ -272,7 +275,7 @@ async function mediaUploadURL(token, socialAccountId, logger) {
272
275
  Authorization: `Bearer ${token}`,
273
276
  'Content-type': 'application/json',
274
277
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
275
- 'LinkedIn-Version': '202311'
278
+ 'LinkedIn-Version': LINKEDIN_VERSION
276
279
  }).send(body);
277
280
  response = {
278
281
  status: 200,
@@ -292,7 +295,7 @@ async function getProfile(urn, token, logger) {
292
295
  }).timeout(5000).set({
293
296
  Authorization: `Bearer ${token}`,
294
297
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
295
- 'LinkedIn-Version': '202311'
298
+ 'LinkedIn-Version': LINKEDIN_VERSION
296
299
  }).then(result => result.body);
297
300
  } catch (error) {
298
301
  (0, _loggerHelpers.loggerError)(logger, `Failed requesting LinkedIn API for profileId ${urn}`, error);
@@ -301,6 +304,8 @@ async function getProfile(urn, token, logger) {
301
304
  (0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for profileId ${urn}`);
302
305
  return profile;
303
306
  }
307
+
308
+ // does this need to exist anymore?
304
309
  async function getOrganization(urn, token, logger) {
305
310
  let [,,, id] = urn.split(':');
306
311
  let organization;
@@ -311,7 +316,7 @@ async function getOrganization(urn, token, logger) {
311
316
  .set({
312
317
  Authorization: `Bearer ${token}`,
313
318
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
314
- 'LinkedIn-Version': '202311'
319
+ 'LinkedIn-Version': LINKEDIN_VERSION
315
320
  }).then(result => result.body);
316
321
  } catch (error) {
317
322
  if (error.response.body.message.includes('ADMIN_ONLY')) {
@@ -324,6 +329,25 @@ async function getOrganization(urn, token, logger) {
324
329
  (0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for organizationId ${urn}`);
325
330
  return organization;
326
331
  }
332
+ async function getOrganizations(urn, token, logger) {
333
+ const [,,, id] = urn.split(':');
334
+ let organizations;
335
+ try {
336
+ organizations = await _superagent.default.get(`${LINKEDIN_API_REST}/organizationsLookup?ids=List(${id})`).timeout(5000) // 5 seconds
337
+ .set({
338
+ Authorization: `Bearer ${token}`,
339
+ 'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
340
+ 'LinkedIn-Version': LINKEDIN_VERSION
341
+ }).then(result => {
342
+ const res = result.body;
343
+ return res.results[id];
344
+ });
345
+ } catch (error) {
346
+ (0, _loggerHelpers.loggerError)(logger, `Failed requesting LinkedIn API for organization id ${id}`, error);
347
+ }
348
+ (0, _loggerHelpers.loggerInfo)(logger, `Finished requesting LinkedIn API for organization id ${id}`);
349
+ return organizations;
350
+ }
327
351
  async function getAllStats(externalId, token, logger) {
328
352
  let response = {};
329
353
  try {
@@ -331,7 +355,7 @@ async function getAllStats(externalId, token, logger) {
331
355
  .set({
332
356
  Authorization: `Bearer ${token}`,
333
357
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
334
- 'LinkedIn-Version': '202311'
358
+ 'LinkedIn-Version': LINKEDIN_VERSION
335
359
  });
336
360
  } catch (error) {
337
361
  (0, _loggerHelpers.loggerError)(logger, 'Error in getAllStats', error);
@@ -374,7 +398,7 @@ async function likedByUser(token, externalId, authorExternalId, logger) {
374
398
  result = await _superagent.default.get(`${LINKEDIN_API}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
375
399
  Authorization: `Bearer ${token}`,
376
400
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
377
- 'LinkedIn-Version': '202311'
401
+ 'LinkedIn-Version': LINKEDIN_VERSION
378
402
  }).then(result => result.body);
379
403
  } catch (error) {
380
404
  (0, _loggerHelpers.loggerError)(logger, 'Error in getLikesByUser', error);
@@ -395,7 +419,7 @@ async function uploadMedia(query, logger) {
395
419
  'Content-Type': 'application/octet-stream',
396
420
  Authorization: `Bearer ${token}`,
397
421
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
398
- 'LinkedIn-Version': '202311'
422
+ 'LinkedIn-Version': LINKEDIN_VERSION
399
423
  }).send(data).catch(err => {
400
424
  (0, _loggerHelpers.loggerError)(logger, "Linkedin Error uploading Media", err);
401
425
  throw err;
@@ -56,13 +56,25 @@ const MeltwaterAttributes = exports.MeltwaterAttributes = {
56
56
  };
57
57
  function loggerDebug(logger, message) {
58
58
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
59
- if (logger) logger.debug(message, meta);
59
+ if (logger) {
60
+ logger.debug(message, meta);
61
+ } else {
62
+ console.log(message, meta);
63
+ }
60
64
  }
61
65
  function loggerInfo(logger, message) {
62
66
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
63
- if (logger) logger.info(message, meta);
67
+ if (logger) {
68
+ logger.info(message, meta);
69
+ } else {
70
+ console.log(message, meta);
71
+ }
64
72
  }
65
73
  function loggerError(logger, message) {
66
74
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
67
- if (logger) logger.error(message, meta);
75
+ if (logger) {
76
+ logger.error(message, meta);
77
+ } else {
78
+ console.log(message, meta);
79
+ }
68
80
  }
@@ -1,5 +1,5 @@
1
1
  import { loggerError } from '../../lib/logger.helpers.js';
2
- const superagent = require('superagent');
2
+ import superagent from 'superagent';
3
3
  import configuration from '../../lib/configuration.js';
4
4
  const gatewayURL = configuration.get('ASSETMANAGER_GATEWAY_URL');
5
5
  export async function getURL(jwt, assetId, logger) {
@@ -3,6 +3,7 @@ import configuration from '../../lib/configuration.js';
3
3
  import { CredentialsApiClient } from '../http/credentialsApi.client.js';
4
4
  import logger from '../../lib/logger.js';
5
5
  import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
6
+ import { getOrganization as getOrganizationNative, getOrganizations as getOrganizationsNative, deleteMessage as deleteMessageNative } from './linkedin.native.js';
6
7
  export class LinkedInApiClient {
7
8
  constructor() {
8
9
  this.credentialsAPI = new CredentialsApiClient();
@@ -109,34 +110,8 @@ export class LinkedInApiClient {
109
110
  const commentId = comment.split(')')[0];
110
111
  let response;
111
112
  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;
113
+ let credential = await this.credentialsAPI.getToken(credentialId, companyId);
114
+ return deleteMessageNative(credential.token, externalId, actorURN, inReplyToId, loggerChild);
140
115
  }
141
116
  async publishComment(document, mediaId) {
142
117
  // command
@@ -459,41 +434,10 @@ export async function getProfile(urn, token) {
459
434
  return profile;
460
435
  }
461
436
  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;
437
+ return getOrganizationNative(urn, token, logger);
478
438
  }
479
439
  export async function getOrganizations(urn, token) {
480
- const [,,, id] = urn.split(':');
481
- let organizations;
482
- try {
483
- organizations = await superagent.get(`${configuration.get('LINKEDIN_API_DATE')}/organizationsLookup?ids=List(${id})`).timeout(5000) // 5 seconds
484
- .set({
485
- Authorization: `Bearer ${token}`,
486
- 'X-RestLi-Protocol-Version': configuration.get('LINKEDIN_API_VERSION'),
487
- 'LinkedIn-Version': '202411'
488
- }).then(result => {
489
- const res = result.body;
490
- return res.results[id];
491
- });
492
- } catch (error) {
493
- logger.error(`Failed requesting LinkedIn API for organization id ${id}`, error);
494
- }
495
- logger.info(`Finished requesting LinkedIn API for organization id ${id}`);
496
- return organizations;
440
+ return getOrganizationsNative(urn, token, logger);
497
441
  }
498
442
  function fixedEncodeURIComponent(str) {
499
443
  return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
@@ -1,7 +1,9 @@
1
1
  import superagent from 'superagent';
2
2
  import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
3
3
  const LINKEDIN_API = "https://api.linkedin.com/v2";
4
+ const LINKEDIN_API_REST = "https://api.linkedin.com/rest";
4
5
  const LINKEDIN_API_VERSION = "2.0.0";
6
+ const LINKEDIN_VERSION = "202411";
5
7
  export async function like(token, externalId, socialAccountId, logger) {
6
8
  let response;
7
9
  let payload = {
@@ -18,7 +20,7 @@ export async function like(token, externalId, socialAccountId, logger) {
18
20
  .set({
19
21
  Authorization: `Bearer ${token}`,
20
22
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
21
- 'LinkedIn-Version': '202311'
23
+ 'LinkedIn-Version': LINKEDIN_VERSION
22
24
  }).send(payload);
23
25
  loggerInfo(logger, `Native Linkedin API Like Mutation Response`, {
24
26
  response: JSON.stringify(response)
@@ -44,7 +46,7 @@ export async function unlike(token, externalId, socialAccountId, logger) {
44
46
  response = await superagent.delete(query).timeout(5000).set({
45
47
  Authorization: `Bearer ${token}`,
46
48
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
47
- 'LinkedIn-Version': '202311'
49
+ 'LinkedIn-Version': LINKEDIN_VERSION
48
50
  });
49
51
  loggerInfo(logger, `Native Linkedin API UNLike Mutation Response`, {
50
52
  response: JSON.stringify(response)
@@ -67,7 +69,7 @@ export async function deleteMessage(token, externalId, sourceId, inReplyToId, lo
67
69
  response = await superagent.delete(query).timeout(5000).set({
68
70
  Authorization: `Bearer ${token}`,
69
71
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
70
- 'LinkedIn-Version': '202311'
72
+ 'LinkedIn-Version': LINKEDIN_VERSION
71
73
  });
72
74
  loggerInfo(logger, `Native Linkedin API Delete Comment Response`, {
73
75
  response: JSON.stringify(response)
@@ -119,7 +121,7 @@ async function publish(token, discussionType, mediaId, inReplyToId, socialAccoun
119
121
  Authorization: `Bearer ${token}`,
120
122
  'Content-Type': 'application/json',
121
123
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
122
- 'LinkedIn-Version': '202311'
124
+ 'LinkedIn-Version': LINKEDIN_VERSION
123
125
  }).send(body);
124
126
  loggerInfo(logger, `Native Linkedin API Publish Comment Response`, {
125
127
  response: JSON.stringify(response)
@@ -156,7 +158,7 @@ async function getImageMedia(mediaId, token, logger) {
156
158
  .set({
157
159
  Authorization: `Bearer ${token}`,
158
160
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
159
- 'LinkedIn-Version': '202311'
161
+ 'LinkedIn-Version': LINKEDIN_VERSION
160
162
  });
161
163
  } catch (error) {
162
164
  loggerError(logger, 'Error in getImageMedia', error);
@@ -191,7 +193,7 @@ export async function getVideoMedia(mediaId, token, logger) {
191
193
  .set({
192
194
  Authorization: `Bearer ${token}`,
193
195
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
194
- 'LinkedIn-Version': '202311'
196
+ 'LinkedIn-Version': LINKEDIN_VERSION
195
197
  });
196
198
  } catch (error) {
197
199
  loggerError(logger, 'Error in getVideoMedia', error);
@@ -253,7 +255,7 @@ export async function mediaUploadURL(token, socialAccountId, logger) {
253
255
  Authorization: `Bearer ${token}`,
254
256
  'Content-type': 'application/json',
255
257
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
256
- 'LinkedIn-Version': '202311'
258
+ 'LinkedIn-Version': LINKEDIN_VERSION
257
259
  }).send(body);
258
260
  response = {
259
261
  status: 200,
@@ -273,7 +275,7 @@ export async function getProfile(urn, token, logger) {
273
275
  }).timeout(5000).set({
274
276
  Authorization: `Bearer ${token}`,
275
277
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
276
- 'LinkedIn-Version': '202311'
278
+ 'LinkedIn-Version': LINKEDIN_VERSION
277
279
  }).then(result => result.body);
278
280
  } catch (error) {
279
281
  loggerError(logger, `Failed requesting LinkedIn API for profileId ${urn}`, error);
@@ -282,6 +284,8 @@ export async function getProfile(urn, token, logger) {
282
284
  loggerInfo(logger, `Finished requesting LinkedIn API for profileId ${urn}`);
283
285
  return profile;
284
286
  }
287
+
288
+ // does this need to exist anymore?
285
289
  export async function getOrganization(urn, token, logger) {
286
290
  let [,,, id] = urn.split(':');
287
291
  let organization;
@@ -292,7 +296,7 @@ export async function getOrganization(urn, token, logger) {
292
296
  .set({
293
297
  Authorization: `Bearer ${token}`,
294
298
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
295
- 'LinkedIn-Version': '202311'
299
+ 'LinkedIn-Version': LINKEDIN_VERSION
296
300
  }).then(result => result.body);
297
301
  } catch (error) {
298
302
  if (error.response.body.message.includes('ADMIN_ONLY')) {
@@ -305,6 +309,25 @@ export async function getOrganization(urn, token, logger) {
305
309
  loggerInfo(logger, `Finished requesting LinkedIn API for organizationId ${urn}`);
306
310
  return organization;
307
311
  }
312
+ export async function getOrganizations(urn, token, logger) {
313
+ const [,,, id] = urn.split(':');
314
+ let organizations;
315
+ try {
316
+ organizations = await superagent.get(`${LINKEDIN_API_REST}/organizationsLookup?ids=List(${id})`).timeout(5000) // 5 seconds
317
+ .set({
318
+ Authorization: `Bearer ${token}`,
319
+ 'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
320
+ 'LinkedIn-Version': LINKEDIN_VERSION
321
+ }).then(result => {
322
+ const res = result.body;
323
+ return res.results[id];
324
+ });
325
+ } catch (error) {
326
+ loggerError(logger, `Failed requesting LinkedIn API for organization id ${id}`, error);
327
+ }
328
+ loggerInfo(logger, `Finished requesting LinkedIn API for organization id ${id}`);
329
+ return organizations;
330
+ }
308
331
  async function getAllStats(externalId, token, logger) {
309
332
  let response = {};
310
333
  try {
@@ -312,7 +335,7 @@ async function getAllStats(externalId, token, logger) {
312
335
  .set({
313
336
  Authorization: `Bearer ${token}`,
314
337
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
315
- 'LinkedIn-Version': '202311'
338
+ 'LinkedIn-Version': LINKEDIN_VERSION
316
339
  });
317
340
  } catch (error) {
318
341
  loggerError(logger, 'Error in getAllStats', error);
@@ -355,7 +378,7 @@ export async function likedByUser(token, externalId, authorExternalId, logger) {
355
378
  result = await superagent.get(`${LINKEDIN_API}/reactions/(actor:${fixedEncodeURIComponent(authorExternalId)},entity:${fixedEncodeURIComponent(externalId)})`).set({
356
379
  Authorization: `Bearer ${token}`,
357
380
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
358
- 'LinkedIn-Version': '202311'
381
+ 'LinkedIn-Version': LINKEDIN_VERSION
359
382
  }).then(result => result.body);
360
383
  } catch (error) {
361
384
  loggerError(logger, 'Error in getLikesByUser', error);
@@ -376,7 +399,7 @@ export async function uploadMedia(query, logger) {
376
399
  'Content-Type': 'application/octet-stream',
377
400
  Authorization: `Bearer ${token}`,
378
401
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
379
- 'LinkedIn-Version': '202311'
402
+ 'LinkedIn-Version': LINKEDIN_VERSION
380
403
  }).send(data).catch(err => {
381
404
  loggerError(logger, "Linkedin Error uploading Media", err);
382
405
  throw err;
@@ -47,14 +47,26 @@ const MeltwaterAttributes = {
47
47
  };
48
48
  export function loggerDebug(logger, message) {
49
49
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
50
- if (logger) logger.debug(message, meta);
50
+ if (logger) {
51
+ logger.debug(message, meta);
52
+ } else {
53
+ console.log(message, meta);
54
+ }
51
55
  }
52
56
  export function loggerInfo(logger, message) {
53
57
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
54
- if (logger) logger.info(message, meta);
58
+ if (logger) {
59
+ logger.info(message, meta);
60
+ } else {
61
+ console.log(message, meta);
62
+ }
55
63
  }
56
64
  export function loggerError(logger, message) {
57
65
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
58
- if (logger) logger.error(message, meta);
66
+ if (logger) {
67
+ logger.error(message, meta);
68
+ } else {
69
+ console.log(message, meta);
70
+ }
59
71
  }
60
72
  export { MeltwaterAttributes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Repository to contain all conversations api services shared across our services",
5
5
  "main": "dist/cjs/data-access/index.js",
6
6
  "module": "dist/esm/data-access/index.js",
@@ -1,5 +1,5 @@
1
1
  import { loggerError } from '../../lib/logger.helpers.js';
2
- const superagent = require('superagent');
2
+ import superagent from 'superagent';
3
3
  import configuration from '../../lib/configuration.js';
4
4
  const gatewayURL = configuration.get(
5
5
  'ASSETMANAGER_GATEWAY_URL'
@@ -3,6 +3,11 @@ import configuration from '../../lib/configuration.js';
3
3
  import { CredentialsApiClient } from '../http/credentialsApi.client.js';
4
4
  import logger from '../../lib/logger.js';
5
5
  import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
6
+ import {
7
+ getOrganization as getOrganizationNative,
8
+ getOrganizations as getOrganizationsNative,
9
+ deleteMessage as deleteMessageNative,
10
+ } from './linkedin.native.js'
6
11
 
7
12
  export class LinkedInApiClient {
8
13
  constructor() {
@@ -135,44 +140,14 @@ export class LinkedInApiClient {
135
140
  inReplyToId
136
141
  )}/comments/${commentId}?actor=${fixedEncodeURIComponent(actorURN)}`;
137
142
 
138
- try {
139
- let credential = await this.credentialsAPI.getToken(
140
- credentialId,
141
- companyId
142
- );
143
+ let credential = await this.credentialsAPI.getToken(
144
+ credentialId,
145
+ companyId
146
+ );
147
+
148
+ return deleteMessageNative(credential.token, externalId, actorURN,inReplyToId, loggerChild)
143
149
 
144
- loggerChild.debug(`${documentId} - trying Delete `, {
145
- query,
146
- });
147
- response = await superagent
148
- .delete(query)
149
- .timeout(5000)
150
- .set({
151
- Authorization: `Bearer ${credential.token}`,
152
- 'X-RestLi-Protocol-Version': configuration.get(
153
- 'LINKEDIN_API_VERSION'
154
- ),
155
- 'LinkedIn-Version': '202311',
156
- });
157
150
 
158
- loggerChild.info(
159
- `Native Linkedin API Delete Comment Response for documentId ${documentId}`,
160
- { status: response.status, ok: response.ok }
161
- );
162
- } catch (err) {
163
- let errorText = '';
164
- if (err && err.response && err.response.text) {
165
- errorText = `Call to linkedin api with documentId ${documentId} failed`;
166
- loggerChild.error(errorText, {
167
- message: JSON.parse(err.response.text),
168
- });
169
- } else {
170
- errorText = `Call to linkedin api with documentId ${documentId} failed`;
171
- loggerChild.error(errorText, err);
172
- }
173
- throw new Error(errorText);
174
- }
175
- return response;
176
151
  }
177
152
 
178
153
  async publishComment(document, mediaId) {
@@ -622,73 +597,11 @@ export async function getProfile(urn, token) {
622
597
  }
623
598
 
624
599
  export async function getOrganization(urn, token) {
625
- let [, , , id] = urn.split(':');
626
-
627
- let organization;
628
- try {
629
- organization = await superagent
630
- .get(`${configuration.get('LINKEDIN_API')}/organizations/${id}`)
631
- .query({
632
- projection:
633
- '(id,localizedName,vanityName,logoV2(original~:playableStreams))',
634
- })
635
- .timeout(5000) // 5 seconds
636
- .set({
637
- Authorization: `Bearer ${token}`,
638
- 'X-RestLi-Protocol-Version': configuration.get(
639
- 'LINKEDIN_API_VERSION'
640
- ),
641
- 'LinkedIn-Version': '202311',
642
- })
643
- .then((result) => result.body);
644
- } catch (error) {
645
- logger.error(
646
- `Failed requesting LinkedIn API for organizationId ${urn}`,
647
- error
648
- );
649
- }
650
-
651
- logger.info(
652
- `Finished requesting LinkedIn API for organizationId ${urn}`
653
- );
654
-
655
- return organization;
600
+ return getOrganizationNative(urn,token,logger);
656
601
  }
657
602
 
658
603
  export async function getOrganizations(urn, token) {
659
- const [, , , id] = urn.split(':');
660
- let organizations;
661
- try {
662
- organizations = await superagent
663
- .get(
664
- `${configuration.get(
665
- 'LINKEDIN_API_DATE'
666
- )}/organizationsLookup?ids=List(${id})`
667
- )
668
- .timeout(5000) // 5 seconds
669
- .set({
670
- Authorization: `Bearer ${token}`,
671
- 'X-RestLi-Protocol-Version': configuration.get(
672
- 'LINKEDIN_API_VERSION'
673
- ),
674
- 'LinkedIn-Version': '202411',
675
- })
676
- .then((result) => {
677
- const res = result.body;
678
- return res.results[id];
679
- });
680
- } catch (error) {
681
- logger.error(
682
- `Failed requesting LinkedIn API for organization id ${id}`,
683
- error
684
- );
685
- }
686
-
687
- logger.info(
688
- `Finished requesting LinkedIn API for organization id ${id}`
689
- );
690
-
691
- return organizations;
604
+ return getOrganizationsNative(urn,token,logger);
692
605
  }
693
606
 
694
607
  function fixedEncodeURIComponent(str) {
@@ -4,7 +4,9 @@ import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.j
4
4
 
5
5
 
6
6
  const LINKEDIN_API = "https://api.linkedin.com/v2";
7
+ const LINKEDIN_API_REST = "https://api.linkedin.com/rest";
7
8
  const LINKEDIN_API_VERSION = "2.0.0";
9
+ const LINKEDIN_VERSION = "202411";
8
10
 
9
11
  export async function like(token, externalId, socialAccountId, logger) {
10
12
  let response;
@@ -22,7 +24,7 @@ export async function like(token, externalId, socialAccountId, logger) {
22
24
  .set({
23
25
  Authorization: `Bearer ${token}`,
24
26
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
25
- 'LinkedIn-Version': '202311',
27
+ 'LinkedIn-Version': LINKEDIN_VERSION,
26
28
  })
27
29
  .send(payload);
28
30
 
@@ -58,7 +60,7 @@ export async function unlike(token, externalId, socialAccountId, logger) {
58
60
  .set({
59
61
  Authorization: `Bearer ${token}`,
60
62
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
61
- 'LinkedIn-Version': '202311',
63
+ 'LinkedIn-Version': LINKEDIN_VERSION,
62
64
  });
63
65
 
64
66
  loggerInfo(logger,
@@ -92,7 +94,7 @@ export async function deleteMessage(token, externalId, sourceId, inReplyToId, lo
92
94
  .set({
93
95
  Authorization: `Bearer ${token}`,
94
96
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
95
- 'LinkedIn-Version': '202311',
97
+ 'LinkedIn-Version': LINKEDIN_VERSION,
96
98
  });
97
99
 
98
100
  loggerInfo(logger,
@@ -158,7 +160,7 @@ async function publish(token,discussionType, mediaId,inReplyToId,socialAccountId
158
160
  Authorization: `Bearer ${token}`,
159
161
  'Content-Type': 'application/json',
160
162
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
161
- 'LinkedIn-Version': '202311',
163
+ 'LinkedIn-Version': LINKEDIN_VERSION,
162
164
  })
163
165
  .send(body);
164
166
 
@@ -219,7 +221,7 @@ async function getImageMedia(mediaId, token, logger) {
219
221
  .set({
220
222
  Authorization: `Bearer ${token}`,
221
223
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
222
- 'LinkedIn-Version': '202311',
224
+ 'LinkedIn-Version': LINKEDIN_VERSION,
223
225
  });
224
226
  } catch (error) {
225
227
  loggerError(logger,'Error in getImageMedia', error);
@@ -268,7 +270,7 @@ export async function getVideoMedia(mediaId, token, logger) {
268
270
  .set({
269
271
  Authorization: `Bearer ${token}`,
270
272
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
271
- 'LinkedIn-Version': '202311',
273
+ 'LinkedIn-Version': LINKEDIN_VERSION,
272
274
  });
273
275
  } catch (error) {
274
276
  loggerError(logger, 'Error in getVideoMedia', error);
@@ -343,7 +345,7 @@ export async function mediaUploadURL(
343
345
  Authorization: `Bearer ${token}`,
344
346
  'Content-type': 'application/json',
345
347
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
346
- 'LinkedIn-Version': '202311',
348
+ 'LinkedIn-Version': LINKEDIN_VERSION,
347
349
  })
348
350
  .send(body);
349
351
 
@@ -375,7 +377,7 @@ export async function getProfile(urn, token, logger) {
375
377
  .set({
376
378
  Authorization: `Bearer ${token}`,
377
379
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
378
- 'LinkedIn-Version': '202311',
380
+ 'LinkedIn-Version': LINKEDIN_VERSION,
379
381
  })
380
382
  .then((result) => result.body);
381
383
  } catch (error) {
@@ -393,6 +395,7 @@ export async function getProfile(urn, token, logger) {
393
395
  return profile;
394
396
  }
395
397
 
398
+ // does this need to exist anymore?
396
399
  export async function getOrganization(urn, token, logger) {
397
400
  let [, , , id] = urn.split(':');
398
401
 
@@ -408,7 +411,7 @@ export async function getOrganization(urn, token, logger) {
408
411
  .set({
409
412
  Authorization: `Bearer ${token}`,
410
413
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
411
- 'LinkedIn-Version': '202311',
414
+ 'LinkedIn-Version': LINKEDIN_VERSION,
412
415
  })
413
416
  .then((result) => result.body);
414
417
  } catch (error) {
@@ -421,7 +424,6 @@ export async function getOrganization(urn, token, logger) {
421
424
  error
422
425
  );
423
426
  }
424
-
425
427
  loggerInfo(logger,
426
428
  `Finished requesting LinkedIn API for organizationId ${urn}`
427
429
  );
@@ -429,6 +431,39 @@ export async function getOrganization(urn, token, logger) {
429
431
  return organization;
430
432
  }
431
433
 
434
+ export async function getOrganizations(urn, token, logger) {
435
+ const [, , , id] = urn.split(':');
436
+ let organizations;
437
+ try {
438
+ organizations = await superagent
439
+ .get(
440
+ `${LINKEDIN_API_REST}/organizationsLookup?ids=List(${id})`
441
+ )
442
+ .timeout(5000) // 5 seconds
443
+ .set({
444
+ Authorization: `Bearer ${token}`,
445
+ 'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
446
+ 'LinkedIn-Version': LINKEDIN_VERSION,
447
+ })
448
+ .then((result) => {
449
+ const res = result.body;
450
+ return res.results[id];
451
+ });
452
+ } catch (error) {
453
+ loggerError(logger,
454
+ `Failed requesting LinkedIn API for organization id ${id}`,
455
+ error
456
+ );
457
+ }
458
+
459
+ loggerInfo(logger,
460
+ `Finished requesting LinkedIn API for organization id ${id}`
461
+ );
462
+
463
+ return organizations;
464
+ }
465
+
466
+
432
467
  async function getAllStats(externalId, token, logger) {
433
468
  let response = {};
434
469
  try {
@@ -442,7 +477,7 @@ async function getAllStats(externalId, token, logger) {
442
477
  .set({
443
478
  Authorization: `Bearer ${token}`,
444
479
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
445
- 'LinkedIn-Version': '202311',
480
+ 'LinkedIn-Version': LINKEDIN_VERSION,
446
481
  });
447
482
  } catch (error) {
448
483
  loggerError(logger,'Error in getAllStats', error);
@@ -495,7 +530,7 @@ export async function likedByUser(
495
530
  .set({
496
531
  Authorization: `Bearer ${token}`,
497
532
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
498
- 'LinkedIn-Version': '202311',
533
+ 'LinkedIn-Version': LINKEDIN_VERSION,
499
534
  })
500
535
  .then((result) => result.body);
501
536
  } catch (error) {
@@ -515,7 +550,7 @@ export async function uploadMedia(query, logger) {
515
550
  'Content-Type': 'application/octet-stream',
516
551
  Authorization: `Bearer ${token}`,
517
552
  'X-RestLi-Protocol-Version': LINKEDIN_API_VERSION,
518
- 'LinkedIn-Version': '202311',
553
+ 'LinkedIn-Version': LINKEDIN_VERSION,
519
554
  })
520
555
  .send(data)
521
556
  .catch((err) => {
@@ -25,18 +25,27 @@ const MeltwaterAttributes = {
25
25
  };
26
26
 
27
27
  export function loggerDebug(logger, message, meta = {}) {
28
- if(logger)
28
+ if(logger){
29
29
  logger.debug(message, meta);
30
+ }else{
31
+ console.log(message,meta);
32
+ }
30
33
  }
31
34
 
32
35
  export function loggerInfo(logger, message, meta = {}) {
33
- if(logger)
36
+ if(logger){
34
37
  logger.info(message, meta);
38
+ }else{
39
+ console.log(message,meta);
40
+ }
35
41
  }
36
42
 
37
43
  export function loggerError(logger, message, meta = {}) {
38
- if(logger)
44
+ if(logger){
39
45
  logger.error(message, meta);
46
+ }else{
47
+ console.log(message,meta);
48
+ }
40
49
  }
41
50
 
42
51
  export { MeltwaterAttributes };