@meltwater/conversations-api-services 1.0.27 → 1.0.29

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.
@@ -19,8 +19,6 @@ exports.unlike = unlike;
19
19
  var _superagent = _interopRequireDefault(require("superagent"));
20
20
  var _externalIdHelpers = require("../../lib/externalId.helpers.js");
21
21
  var _loggerHelpers = require("../../lib/logger.helpers.js");
22
- var _httpError = require("../../errors/http-error.js");
23
- var _engageError = require("../../errors/engage-error.js");
24
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
25
23
  const FACEBOOK_URL = 'https://graph.facebook.com';
26
24
  async function shareCount(token, externalId, logger) {
@@ -306,7 +304,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
306
304
  (0, _loggerHelpers.loggerError)(logger, `Failed to call facebook api`, err);
307
305
  }
308
306
  if (response.status) {
309
- throw new _httpError.EngageHttpError(response.status, response.statusText, response.body, response.headers);
307
+ throw new Error(response.statusText);
310
308
  }
311
309
  throw err;
312
310
  }
@@ -314,7 +312,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
314
312
  logger.error(logger, `Failed to call facebook api`, {
315
313
  responseBody: JSON.stringify(response.body)
316
314
  });
317
- throw new _engageError.EngageError(response.status, `Failed to call facebook api ${response.body}`);
315
+ throw new Error(`Failed to call facebook api ${response.body}`);
318
316
  }
319
317
  return response;
320
318
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.LinkedInApiClient = void 0;
7
7
  exports.getOrganization = getOrganization;
8
+ exports.getOrganizations = getOrganizations;
8
9
  exports.getProfile = getProfile;
9
10
  var _superagent = _interopRequireDefault(require("superagent"));
10
11
  var _configuration = _interopRequireDefault(require("../../lib/configuration.js"));
@@ -486,6 +487,25 @@ async function getOrganization(urn, token) {
486
487
  _logger.default.info(`Finished requesting LinkedIn API for organizationId ${urn}`);
487
488
  return organization;
488
489
  }
490
+ 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
+ this.logger.error(`Failed requesting LinkedIn API for organization id ${id}`, error);
505
+ }
506
+ this.logger.info(`Finished requesting LinkedIn API for organization id ${id}`);
507
+ return organizations;
508
+ }
489
509
  function fixedEncodeURIComponent(str) {
490
510
  return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
491
511
  }
@@ -37,7 +37,8 @@ const DocumentHelperFunctions = {
37
37
  };
38
38
  const LinkedInHelpers = {
39
39
  getOrganization: _linkedInApiClient.getOrganization,
40
- getProfile: _linkedInApiClient.getProfile
40
+ getProfile: _linkedInApiClient.getProfile,
41
+ getOrganizations: _linkedInApiClient.getOrganizations
41
42
  };
42
43
  var _default = exports.default = {
43
44
  InstagramNative,
@@ -42,7 +42,7 @@ function isMention(_ref, credential) {
42
42
  if (authorExternalId && credential.social_account_id && authorExternalId === credential.social_account_id || authorHandle?.length && (authorHandle.toLowerCase() === credential.username?.toLowerCase || authorHandle.toLowerCase() === credential.handle?.toLowerCase())) {
43
43
  return false;
44
44
  }
45
- let retIsMention = (['og', 're', 'qt'].includes(discussionType) || discussionType === 'dm' && socialOriginType === 'instagram') && (mentions?.length && mentions.some(mention => mention.toLowerCase() === credential.pageName?.toLowerCase() || mention.toLowerCase() === credential.target_page_name?.toLowerCase() || mention.toLowerCase() === credential.userName?.toLowerCase() || mention.toLowerCase() === credential.username?.toLowerCase()) || isMention && socialOriginType === 'facebook');
45
+ let retIsMention = (['og', 're', 'qt'].includes(discussionType) || discussionType === 'dm' && socialOriginType === 'instagram') && (mentions?.length && mentions.some(mention => mention.toLowerCase() === credential.pageName?.toLowerCase() || mention.toLowerCase() === credential.target_page_name?.toLowerCase() || mention.toLowerCase() === credential.userName?.toLowerCase() || mention.toLowerCase() === credential.username?.toLowerCase() || mention.toLowerCase() === credential.social_account_id?.toLowerCase() || mention.toLowerCase() === credential.SocialAccountId?.toLowerCase()) || isMention && socialOriginType === 'facebook');
46
46
  if (providerSpecific) {
47
47
  let hasMention = providerSpecific.some(_ref2 => {
48
48
  let {
@@ -1,8 +1,6 @@
1
1
  import superagent from 'superagent';
2
2
  import { removePrefix } from '../../lib/externalId.helpers.js';
3
3
  import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
4
- import { EngageHttpError } from '../../errors/http-error.js';
5
- import { EngageError } from '../../errors/engage-error.js';
6
4
  const FACEBOOK_URL = 'https://graph.facebook.com';
7
5
  export async function shareCount(token, externalId, logger) {
8
6
  try {
@@ -287,7 +285,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
287
285
  loggerError(logger, `Failed to call facebook api`, err);
288
286
  }
289
287
  if (response.status) {
290
- throw new EngageHttpError(response.status, response.statusText, response.body, response.headers);
288
+ throw new Error(response.statusText);
291
289
  }
292
290
  throw err;
293
291
  }
@@ -295,7 +293,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
295
293
  logger.error(logger, `Failed to call facebook api`, {
296
294
  responseBody: JSON.stringify(response.body)
297
295
  });
298
- throw new EngageError(response.status, `Failed to call facebook api ${response.body}`);
296
+ throw new Error(`Failed to call facebook api ${response.body}`);
299
297
  }
300
298
  return response;
301
299
  }
@@ -476,6 +476,25 @@ export async function getOrganization(urn, token) {
476
476
  logger.info(`Finished requesting LinkedIn API for organizationId ${urn}`);
477
477
  return organization;
478
478
  }
479
+ 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
+ this.logger.error(`Failed requesting LinkedIn API for organization id ${id}`, error);
494
+ }
495
+ this.logger.info(`Finished requesting LinkedIn API for organization id ${id}`);
496
+ return organizations;
497
+ }
479
498
  function fixedEncodeURIComponent(str) {
480
499
  return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
481
500
  }
@@ -9,7 +9,7 @@ import { IdentityServicesClient } from './http/identityServices.client.js';
9
9
  import { InstagramApiClient } from './http/instagramApi.client.js';
10
10
  import { InstagramVideoClient } from './http/InstagramVideoClient.js';
11
11
  import { IRClient } from './http/ir.client.js';
12
- import { LinkedInApiClient, getOrganization, getProfile } from './http/linkedInApi.client.js';
12
+ import { LinkedInApiClient, getOrganization, getProfile, getOrganizations } from './http/linkedInApi.client.js';
13
13
  import { TikTokApiClient } from './http/tiktokApi.client.js';
14
14
  import { MasfClient } from './http/masf.client.js';
15
15
  import { WarpZoneApiClient } from './http/WarpZoneApi.client.js';
@@ -29,7 +29,8 @@ const DocumentHelperFunctions = {
29
29
  };
30
30
  const LinkedInHelpers = {
31
31
  getOrganization,
32
- getProfile
32
+ getProfile,
33
+ getOrganizations
33
34
  };
34
35
  export default {
35
36
  InstagramNative,
@@ -36,7 +36,7 @@ export function isMention(_ref, credential) {
36
36
  if (authorExternalId && credential.social_account_id && authorExternalId === credential.social_account_id || authorHandle?.length && (authorHandle.toLowerCase() === credential.username?.toLowerCase || authorHandle.toLowerCase() === credential.handle?.toLowerCase())) {
37
37
  return false;
38
38
  }
39
- let retIsMention = (['og', 're', 'qt'].includes(discussionType) || discussionType === 'dm' && socialOriginType === 'instagram') && (mentions?.length && mentions.some(mention => mention.toLowerCase() === credential.pageName?.toLowerCase() || mention.toLowerCase() === credential.target_page_name?.toLowerCase() || mention.toLowerCase() === credential.userName?.toLowerCase() || mention.toLowerCase() === credential.username?.toLowerCase()) || isMention && socialOriginType === 'facebook');
39
+ let retIsMention = (['og', 're', 'qt'].includes(discussionType) || discussionType === 'dm' && socialOriginType === 'instagram') && (mentions?.length && mentions.some(mention => mention.toLowerCase() === credential.pageName?.toLowerCase() || mention.toLowerCase() === credential.target_page_name?.toLowerCase() || mention.toLowerCase() === credential.userName?.toLowerCase() || mention.toLowerCase() === credential.username?.toLowerCase() || mention.toLowerCase() === credential.social_account_id?.toLowerCase() || mention.toLowerCase() === credential.SocialAccountId?.toLowerCase()) || isMention && socialOriginType === 'facebook');
40
40
  if (providerSpecific) {
41
41
  let hasMention = providerSpecific.some(_ref2 => {
42
42
  let {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
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,8 +1,6 @@
1
1
  import superagent from 'superagent';
2
2
  import { removePrefix } from '../../lib/externalId.helpers.js';
3
3
  import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
4
- import { EngageHttpError } from '../../errors/http-error.js';
5
- import { EngageError } from '../../errors/engage-error.js';
6
4
 
7
5
  const FACEBOOK_URL = 'https://graph.facebook.com';
8
6
 
@@ -477,7 +475,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
477
475
  );
478
476
  }
479
477
  if(response.status){
480
- throw new EngageHttpError(response.status, response.statusText, response.body, response.headers);
478
+ throw new Error(response.statusText);
481
479
  }
482
480
  throw err;
483
481
  }
@@ -487,8 +485,7 @@ async function postApi(apiUrl, accessToken, payload, logger) {
487
485
  `Failed to call facebook api`,
488
486
  { responseBody: JSON.stringify(response.body) }
489
487
  );
490
- throw new EngageError(
491
- response.status,
488
+ throw new Error(
492
489
  `Failed to call facebook api ${response.body}`
493
490
  );
494
491
  }
@@ -654,6 +654,43 @@ export async function getOrganization(urn, token) {
654
654
 
655
655
  return organization;
656
656
  }
657
+
658
+ 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
+ this.logger.error(
682
+ `Failed requesting LinkedIn API for organization id ${id}`,
683
+ error
684
+ );
685
+ }
686
+
687
+ this.logger.info(
688
+ `Finished requesting LinkedIn API for organization id ${id}`
689
+ );
690
+
691
+ return organizations;
692
+ }
693
+
657
694
  function fixedEncodeURIComponent(str) {
658
695
  return encodeURIComponent(str).replace('(', '%28').replace(')', '%29');
659
696
  }
@@ -9,12 +9,17 @@ import { IdentityServicesClient } from './http/identityServices.client.js';
9
9
  import { InstagramApiClient } from './http/instagramApi.client.js';
10
10
  import { InstagramVideoClient } from './http/InstagramVideoClient.js';
11
11
  import { IRClient } from './http/ir.client.js';
12
- import { LinkedInApiClient, getOrganization, getProfile } from './http/linkedInApi.client.js';
12
+ import {
13
+ LinkedInApiClient,
14
+ getOrganization,
15
+ getProfile,
16
+ getOrganizations,
17
+ } from './http/linkedInApi.client.js';
13
18
  import { TikTokApiClient } from './http/tiktokApi.client.js';
14
19
  import { MasfClient } from './http/masf.client.js';
15
20
  import { WarpZoneApiClient } from './http/WarpZoneApi.client.js';
16
21
  import * as messageHelpers from '../lib/message.helpers.js';
17
- import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
22
+ import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
18
23
  import * as hiddenHelpers from '../lib/hidden.helpers.js';
19
24
  import * as FacebookNative from './http/facebook.native.js';
20
25
  import * as TiktokNative from './http/tiktok.native.js';
@@ -27,11 +32,12 @@ const DocumentHelperFunctions = {
27
32
  ...messageHelpers,
28
33
  ...applicationTagFunctions,
29
34
  ...hiddenHelpers,
30
- }
35
+ };
31
36
  const LinkedInHelpers = {
32
37
  getOrganization,
33
38
  getProfile,
34
- }
39
+ getOrganizations,
40
+ };
35
41
 
36
42
  export default {
37
43
  InstagramNative,
@@ -69,9 +69,13 @@ export function isMention({
69
69
  mention.toLowerCase() ===
70
70
  credential.target_page_name?.toLowerCase() ||
71
71
  mention.toLowerCase() ===
72
- credential.userName?.toLowerCase()||
72
+ credential.userName?.toLowerCase() ||
73
73
  mention.toLowerCase() ===
74
- credential.username?.toLowerCase()
74
+ credential.username?.toLowerCase() ||
75
+ mention.toLowerCase() ===
76
+ credential.social_account_id?.toLowerCase() ||
77
+ mention.toLowerCase() ===
78
+ credential.SocialAccountId?.toLowerCase()
75
79
  ))
76
80
  ||
77
81
  (isMention && socialOriginType === 'facebook'));
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EngageError = void 0;
7
- class EngageError extends Error {
8
- code;
9
- constructor(code, message) {
10
- super(message);
11
- Object.setPrototypeOf(this, new.target.prototype);
12
- this.name = this.constructor.name;
13
- this.code = code;
14
- }
15
- }
16
- exports.EngageError = EngageError;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EngageHttpError = void 0;
7
- var _engageError = require("./engage-error");
8
- class EngageHttpError extends _engageError.EngageError {
9
- status;
10
- statusText;
11
- response;
12
- headers;
13
- constructor(status, statusText, response, headers) {
14
- super(`HTTP ${status}: ${statusText}`, statusText);
15
- Object.setPrototypeOf(this, new.target.prototype);
16
- this.name = this.constructor.name;
17
- this.status = status;
18
- this.statusText = statusText;
19
- this.response = response;
20
- this.headers = headers;
21
- }
22
- }
23
- exports.EngageHttpError = EngageHttpError;
@@ -1,9 +0,0 @@
1
- export class EngageError extends Error {
2
- code;
3
- constructor(code, message) {
4
- super(message);
5
- Object.setPrototypeOf(this, new.target.prototype);
6
- this.name = this.constructor.name;
7
- this.code = code;
8
- }
9
- }
@@ -1,16 +0,0 @@
1
- import { EngageError } from "./engage-error";
2
- export class EngageHttpError extends EngageError {
3
- status;
4
- statusText;
5
- response;
6
- headers;
7
- constructor(status, statusText, response, headers) {
8
- super(`HTTP ${status}: ${statusText}`, statusText);
9
- Object.setPrototypeOf(this, new.target.prototype);
10
- this.name = this.constructor.name;
11
- this.status = status;
12
- this.statusText = statusText;
13
- this.response = response;
14
- this.headers = headers;
15
- }
16
- }
@@ -1,11 +0,0 @@
1
- export class EngageError extends Error {
2
- code;
3
-
4
- constructor(code, message) {
5
- super(message);
6
- Object.setPrototypeOf(this, new.target.prototype);
7
-
8
- this.name = this.constructor.name;
9
- this.code = code;
10
- }
11
- }
@@ -1,19 +0,0 @@
1
- import { EngageError } from "./engage-error";
2
-
3
- export class EngageHttpError extends EngageError {
4
- status;
5
- statusText;
6
- response;
7
- headers;
8
-
9
- constructor(status, statusText, response, headers) {
10
- super(`HTTP ${status}: ${statusText}`, statusText);
11
- Object.setPrototypeOf(this, new.target.prototype);
12
-
13
- this.name = this.constructor.name;
14
- this.status = status;
15
- this.statusText = statusText;
16
- this.response = response;
17
- this.headers = headers;
18
- }
19
- }