@meltwater/conversations-api-services 1.1.19 → 1.1.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.
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 20.11.0
1
+ 20.17.0
@@ -36,9 +36,6 @@ class IRClient {
36
36
  this.traceId = traceId;
37
37
  this.metrics = metrics;
38
38
  }
39
- async addRevisionsToDocuments(operations) {
40
- return await addRevisionsToDocuments(operations, this.company._id, _logger.default);
41
- }
42
39
  async modifyDocuments(operations) {
43
40
  let retryAttempt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
44
41
  await this.init();
@@ -217,23 +214,14 @@ class IRClient {
217
214
  return `engage_${this.company._id}_${this.traceId}_${(0, _uuid.v4)()}`;
218
215
  }
219
216
  }
217
+
218
+ // everywhere in use it is surrounded by try catch so not needed here for better logging
220
219
  exports.default = IRClient;
221
- async function addRevisionsToDocuments(operations, companyId, logger) {
220
+ async function addRevisionsToDocuments(operations, companyId) {
222
221
  const url = `${documentRevisionsServiceUrl}/${companyId}/`;
223
- let result;
224
- try {
225
- result = await _superagent.default.patch(url).query({
226
- apikey: documentServiceKey
227
- }).set('x-client-name', 'engage-conversations').send(operations).then(result => result.body);
228
- } catch (error) {
229
- (0, _loggerHelpers.loggerError)(logger, `Failed adding a revisions with operations`, error, {
230
- url,
231
- [_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
232
- operations: JSON.stringify(operations)
233
- });
234
- return;
235
- }
236
- return result;
222
+ return await _superagent.default.patch(url).query({
223
+ apikey: documentServiceKey
224
+ }).set('x-client-name', 'engage-conversations').send(operations).then(result => result.body);
237
225
  }
238
226
  async function markAsComplete(messageIds, companyId, logger) {
239
227
  return reviseDocumentHelper(messageIds, 'markAsComplete', companyId, logger);
@@ -295,11 +283,9 @@ async function reviseDocumentHelper(messageIds, revisionType, companyId, logger)
295
283
  (0, _loggerHelpers.loggerInfo)(logger, `Sending revision for ${revisionType} for companyId: ${companyId}`, {
296
284
  operations: JSON.stringify(operations)
297
285
  });
298
- revisionPromises.push(addRevisionsToDocuments(operations, companyId, logger));
286
+ revisionPromises.push(addRevisionsToDocuments(operations, companyId));
299
287
  } catch (error) {
300
- (0, _loggerHelpers.loggerError)(logger, `Error marking as ${revisionType} in IR for ${messageIds.length} document(s). Unable to save revision.`, error, {
301
- messageIds
302
- });
288
+ (0, _loggerHelpers.loggerError)(logger, `Error marking as ${revisionType} in IR for ${messageIds.length} document(s). Unable to save revision.`, error);
303
289
  }
304
290
  }
305
291
  return await Promise.all(revisionPromises);
@@ -354,7 +354,7 @@ async function getProfile(urn, token, logger) {
354
354
  let [,,, id] = urn.split(':');
355
355
  let profile;
356
356
  try {
357
- profile = await _superagent.default.get(`${LINKEDIN_API}/people/(id:${id})`).query({
357
+ profile = await _superagent.default.get(`${LINKEDIN_API}/people/(id:${fixedEncodeURIComponent(id)})`).query({
358
358
  projection: '(id,localizedFirstName,localizedLastName,vanityName,profilePicture(displayImage~:playableStreams))'
359
359
  }).timeout(5000).set({
360
360
  Authorization: `Bearer ${token}`,
@@ -374,7 +374,7 @@ async function getOrganization(urn, token, logger) {
374
374
  let [,,, id] = urn.split(':');
375
375
  let organization;
376
376
  try {
377
- organization = await _superagent.default.get(`${LINKEDIN_API}/organizations/${id}`).query({
377
+ organization = await _superagent.default.get(`${LINKEDIN_API}/organizations/${fixedEncodeURIComponent(id)}`).query({
378
378
  projection: '(id,localizedName,vanityName,logoV2(original~:playableStreams))'
379
379
  }).timeout(5000) // 5 seconds
380
380
  .set({
@@ -194,7 +194,7 @@ async function sendRequest(token) {
194
194
  }
195
195
  if (response.status !== 200) {
196
196
  (0, _loggerHelpers.loggerError)(logger, `Failed to call tiktok api`, {
197
- responseBody: JSON.stringify(response.body)
197
+ [_loggerHelpers.MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(response.body)
198
198
  });
199
199
  let error = new Error(`Failed to call tiktok api`);
200
200
  error.code = response.status;
@@ -8,6 +8,17 @@ exports.loggerDebug = loggerDebug;
8
8
  exports.loggerError = loggerError;
9
9
  exports.loggerInfo = loggerInfo;
10
10
  exports.loggerWarn = loggerWarn;
11
+ const {
12
+ RUN_PRECOG_AS = 'Conversations-Services',
13
+ LOGNAMESPACE = 'phoenix-local'
14
+ } = process.env;
15
+ const getServiceName = () => {
16
+ const rep = RUN_PRECOG_AS.replace(/_/g, '-');
17
+ return `precog-service-${rep.toLowerCase()}-${process.env.NODE_ENV}`;
18
+ };
19
+ const getInternalHeader = key => {
20
+ return `internal.${LOGNAMESPACE}.${key || 'unknown'}`;
21
+ };
11
22
  const MeltwaterAttributes = exports.MeltwaterAttributes = {
12
23
  COMPANYID: 'meltwater.company.id',
13
24
  // Unique identifier of a company as it applies to meltwater search
@@ -53,7 +64,9 @@ const MeltwaterAttributes = exports.MeltwaterAttributes = {
53
64
  // The expiration of the auth credentials.
54
65
  AUTHPERMISSIONS: 'meltwater.auth.permissions',
55
66
  // List of auth permermissions.
56
- USERID: 'user.id' // ID of the user
67
+ USERID: 'user.id',
68
+ // ID of the user
69
+ PAYLOADDATA: getInternalHeader('payloadData') // Post data for warpzone
57
70
  };
58
71
  function loggerDebug(logger, message) {
59
72
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -25,9 +25,6 @@ export default class IRClient {
25
25
  this.traceId = traceId;
26
26
  this.metrics = metrics;
27
27
  }
28
- async addRevisionsToDocuments(operations) {
29
- return await addRevisionsToDocuments(operations, this.company._id, logger);
30
- }
31
28
  async modifyDocuments(operations) {
32
29
  let retryAttempt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
33
30
  await this.init();
@@ -206,22 +203,13 @@ export default class IRClient {
206
203
  return `engage_${this.company._id}_${this.traceId}_${v4()}`;
207
204
  }
208
205
  }
209
- export async function addRevisionsToDocuments(operations, companyId, logger) {
206
+
207
+ // everywhere in use it is surrounded by try catch so not needed here for better logging
208
+ export async function addRevisionsToDocuments(operations, companyId) {
210
209
  const url = `${documentRevisionsServiceUrl}/${companyId}/`;
211
- let result;
212
- try {
213
- result = await superagent.patch(url).query({
214
- apikey: documentServiceKey
215
- }).set('x-client-name', 'engage-conversations').send(operations).then(result => result.body);
216
- } catch (error) {
217
- loggerError(logger, `Failed adding a revisions with operations`, error, {
218
- url,
219
- [MeltwaterAttributes.COMPANYID]: companyId,
220
- operations: JSON.stringify(operations)
221
- });
222
- return;
223
- }
224
- return result;
210
+ return await superagent.patch(url).query({
211
+ apikey: documentServiceKey
212
+ }).set('x-client-name', 'engage-conversations').send(operations).then(result => result.body);
225
213
  }
226
214
  export async function markAsComplete(messageIds, companyId, logger) {
227
215
  return reviseDocumentHelper(messageIds, 'markAsComplete', companyId, logger);
@@ -283,11 +271,9 @@ async function reviseDocumentHelper(messageIds, revisionType, companyId, logger)
283
271
  loggerInfo(logger, `Sending revision for ${revisionType} for companyId: ${companyId}`, {
284
272
  operations: JSON.stringify(operations)
285
273
  });
286
- revisionPromises.push(addRevisionsToDocuments(operations, companyId, logger));
274
+ revisionPromises.push(addRevisionsToDocuments(operations, companyId));
287
275
  } catch (error) {
288
- loggerError(logger, `Error marking as ${revisionType} in IR for ${messageIds.length} document(s). Unable to save revision.`, error, {
289
- messageIds
290
- });
276
+ loggerError(logger, `Error marking as ${revisionType} in IR for ${messageIds.length} document(s). Unable to save revision.`, error);
291
277
  }
292
278
  }
293
279
  return await Promise.all(revisionPromises);
@@ -332,7 +332,7 @@ export async function getProfile(urn, token, logger) {
332
332
  let [,,, id] = urn.split(':');
333
333
  let profile;
334
334
  try {
335
- profile = await superagent.get(`${LINKEDIN_API}/people/(id:${id})`).query({
335
+ profile = await superagent.get(`${LINKEDIN_API}/people/(id:${fixedEncodeURIComponent(id)})`).query({
336
336
  projection: '(id,localizedFirstName,localizedLastName,vanityName,profilePicture(displayImage~:playableStreams))'
337
337
  }).timeout(5000).set({
338
338
  Authorization: `Bearer ${token}`,
@@ -352,7 +352,7 @@ export async function getOrganization(urn, token, logger) {
352
352
  let [,,, id] = urn.split(':');
353
353
  let organization;
354
354
  try {
355
- organization = await superagent.get(`${LINKEDIN_API}/organizations/${id}`).query({
355
+ organization = await superagent.get(`${LINKEDIN_API}/organizations/${fixedEncodeURIComponent(id)}`).query({
356
356
  projection: '(id,localizedName,vanityName,logoV2(original~:playableStreams))'
357
357
  }).timeout(5000) // 5 seconds
358
358
  .set({
@@ -1,5 +1,5 @@
1
1
  import superagent from 'superagent';
2
- import { loggerError } from '../../lib/logger.helpers.js';
2
+ import { loggerError, MeltwaterAttributes } from '../../lib/logger.helpers.js';
3
3
  import { removePrefix } from '../../lib/externalId.helpers.js';
4
4
  const TIKTOK_API_URL = 'https://business-api.tiktok.com/open_api/v1.3/business/';
5
5
  export async function comment(token, business_id, video_id, text, logger) {
@@ -177,7 +177,7 @@ async function sendRequest(token) {
177
177
  }
178
178
  if (response.status !== 200) {
179
179
  loggerError(logger, `Failed to call tiktok api`, {
180
- responseBody: JSON.stringify(response.body)
180
+ [MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(response.body)
181
181
  });
182
182
  let error = new Error(`Failed to call tiktok api`);
183
183
  error.code = response.status;
@@ -1,3 +1,14 @@
1
+ const {
2
+ RUN_PRECOG_AS = 'Conversations-Services',
3
+ LOGNAMESPACE = 'phoenix-local'
4
+ } = process.env;
5
+ const getServiceName = () => {
6
+ const rep = RUN_PRECOG_AS.replace(/_/g, '-');
7
+ return `precog-service-${rep.toLowerCase()}-${process.env.NODE_ENV}`;
8
+ };
9
+ const getInternalHeader = key => {
10
+ return `internal.${LOGNAMESPACE}.${key || 'unknown'}`;
11
+ };
1
12
  const MeltwaterAttributes = {
2
13
  COMPANYID: 'meltwater.company.id',
3
14
  // Unique identifier of a company as it applies to meltwater search
@@ -43,7 +54,9 @@ const MeltwaterAttributes = {
43
54
  // The expiration of the auth credentials.
44
55
  AUTHPERMISSIONS: 'meltwater.auth.permissions',
45
56
  // List of auth permermissions.
46
- USERID: 'user.id' // ID of the user
57
+ USERID: 'user.id',
58
+ // ID of the user
59
+ PAYLOADDATA: getInternalHeader('payloadData') // Post data for warpzone
47
60
  };
48
61
  export function loggerDebug(logger, message) {
49
62
  let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
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",
@@ -50,6 +50,7 @@
50
50
  "lodash": "^4.17.21",
51
51
  "moment": "^2.30.1",
52
52
  "prom-client": "^15.1.0",
53
+ "sha.js": ">=2.4.12",
53
54
  "superagent": "^8.1.2",
54
55
  "winston": "^3.11.0"
55
56
  },
@@ -27,10 +27,6 @@ export default class IRClient {
27
27
  this.metrics = metrics;
28
28
  }
29
29
 
30
- async addRevisionsToDocuments(operations) {
31
- return await addRevisionsToDocuments(operations,this.company._id,logger);
32
- }
33
-
34
30
  async modifyDocuments(operations, retryAttempt = 0) {
35
31
  await this.init();
36
32
  const wait = 100;
@@ -276,29 +272,18 @@ export default class IRClient {
276
272
  }
277
273
  }
278
274
 
279
- export async function addRevisionsToDocuments(operations, companyId, logger) {
275
+ // everywhere in use it is surrounded by try catch so not needed here for better logging
276
+ export async function addRevisionsToDocuments(operations, companyId) {
280
277
  const url = `${documentRevisionsServiceUrl}/${companyId}/`;
281
- let result;
282
-
283
- try {
284
- result = await superagent
285
- .patch(url)
286
- .query({
287
- apikey: documentServiceKey,
288
- })
289
- .set('x-client-name', 'engage-conversations')
290
- .send(operations)
291
- .then((result) => result.body);
292
- } catch (error) {
293
- loggerError(logger,`Failed adding a revisions with operations`, error, {
294
- url,
295
- [MeltwaterAttributes.COMPANYID]: companyId,
296
- operations: JSON.stringify(operations)
297
- });
298
- return;
299
- }
300
278
 
301
- return result;
279
+ return await superagent
280
+ .patch(url)
281
+ .query({
282
+ apikey: documentServiceKey,
283
+ })
284
+ .set('x-client-name', 'engage-conversations')
285
+ .send(operations)
286
+ .then((result) => result.body);
302
287
  }
303
288
 
304
289
  export async function markAsComplete(messageIds, companyId, logger) {
@@ -386,13 +371,12 @@ async function reviseDocumentHelper(messageIds, revisionType, companyId, logger)
386
371
  { operations: JSON.stringify(operations) }
387
372
  );
388
373
  revisionPromises.push(
389
- addRevisionsToDocuments(operations,companyId,logger)
374
+ addRevisionsToDocuments(operations,companyId)
390
375
  );
391
376
  } catch (error) {
392
377
  loggerError(logger,
393
378
  `Error marking as ${revisionType} in IR for ${messageIds.length} document(s). Unable to save revision.`,
394
- error,
395
- { messageIds }
379
+ error
396
380
  );
397
381
  }
398
382
  }
@@ -441,7 +441,7 @@ export async function getProfile(urn, token, logger) {
441
441
  let profile;
442
442
  try {
443
443
  profile = await superagent
444
- .get(`${LINKEDIN_API}/people/(id:${id})`)
444
+ .get(`${LINKEDIN_API}/people/(id:${fixedEncodeURIComponent(id)})`)
445
445
  .query({
446
446
  projection:
447
447
  '(id,localizedFirstName,localizedLastName,vanityName,profilePicture(displayImage~:playableStreams))',
@@ -475,7 +475,7 @@ export async function getOrganization(urn, token, logger) {
475
475
  let organization;
476
476
  try {
477
477
  organization = await superagent
478
- .get(`${LINKEDIN_API}/organizations/${id}`)
478
+ .get(`${LINKEDIN_API}/organizations/${fixedEncodeURIComponent(id)}`)
479
479
  .query({
480
480
  projection:
481
481
  '(id,localizedName,vanityName,logoV2(original~:playableStreams))',
@@ -1,5 +1,5 @@
1
1
  import superagent from 'superagent';
2
- import { loggerError } from '../../lib/logger.helpers.js';
2
+ import { loggerError, MeltwaterAttributes } from '../../lib/logger.helpers.js';
3
3
  import { removePrefix } from '../../lib/externalId.helpers.js';
4
4
 
5
5
  const TIKTOK_API_URL =
@@ -267,7 +267,7 @@ async function sendRequest(token, paramString = '', logger) {
267
267
 
268
268
  if (response.status !== 200) {
269
269
  loggerError(logger, `Failed to call tiktok api`, {
270
- responseBody: JSON.stringify(response.body),
270
+ [MeltwaterAttributes.PAYLOADDATA]: JSON.stringify(response.body),
271
271
  });
272
272
  let error = new Error(`Failed to call tiktok api`);
273
273
  error.code = response.status;
@@ -1,3 +1,15 @@
1
+ const { RUN_PRECOG_AS = 'Conversations-Services', LOGNAMESPACE = 'phoenix-local' } = process.env;
2
+
3
+ const getServiceName = () => {
4
+ const rep = RUN_PRECOG_AS.replace(/_/g, '-');
5
+ return `precog-service-${rep.toLowerCase()}-${process.env.NODE_ENV}`;
6
+ };
7
+
8
+
9
+ const getInternalHeader = (key) => {
10
+ return `internal.${LOGNAMESPACE}.${key || 'unknown'}`;
11
+ };
12
+
1
13
  const MeltwaterAttributes = {
2
14
  COMPANYID: 'meltwater.company.id', // Unique identifier of a company as it applies to meltwater search
3
15
  DOCUMENTID: 'meltwater.document.id', // Unique identifier of a document indexed into search
@@ -22,6 +34,7 @@ const MeltwaterAttributes = {
22
34
  AUTHEXP: 'meltwater.auth.exp', // The expiration of the auth credentials.
23
35
  AUTHPERMISSIONS: 'meltwater.auth.permissions', // List of auth permermissions.
24
36
  USERID: 'user.id', // ID of the user
37
+ PAYLOADDATA: getInternalHeader('payloadData'), // Post data for warpzone
25
38
  };
26
39
 
27
40
  export function loggerDebug(logger, message, meta = {}) {