@meltwater/conversations-api-services 1.0.11 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Repository to contain all conversations api services shared across our services",
5
5
  "type": "module",
6
6
  "main": "src/data-access/index.js",
@@ -1,11 +1,12 @@
1
1
  import superagent from 'superagent';
2
2
  import logger from '../../lib/logger.js';
3
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
3
4
 
4
5
  const { ASSET_MANAGER_TVM_API_KEY, ASSET_MANAGER_TVM_URL } = process.env;
5
6
 
6
7
  class AssetManagerTVMRepository {
7
8
  apiKey;
8
- constructor() {}
9
+ constructor() { }
9
10
 
10
11
  async get(companyId) {
11
12
  let response;
@@ -21,7 +22,9 @@ class AssetManagerTVMRepository {
21
22
  })
22
23
  .then((result) => result.body);
23
24
  } catch (error) {
24
- logger.error(error, { 'meltwater.company.id': companyId });
25
+ logger.error("Failed requesting Asset Manager TVM API", error, {
26
+ [MeltwaterAttributes.COMPANYID]: companyId
27
+ });
25
28
  throw error;
26
29
  }
27
30
 
@@ -1,6 +1,7 @@
1
1
  import superagent from 'superagent';
2
2
  import logger from '../../lib/logger.js';
3
3
  import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
4
5
 
5
6
  export class CompanyApiClient {
6
7
  constructor({ services }) {
@@ -20,10 +21,9 @@ export class CompanyApiClient {
20
21
  .then((result) => result.body);
21
22
  } catch (error) {
22
23
  logger.error(
23
- `Failed requesting Companies Api for companyId ${companyId} retry ${retries}`,
24
- error,
25
- { 'meltwater.company.id': companyId }
26
- );
24
+ `Failed requesting Companies Api for companyId ${companyId} retry ${retries}`, error, {
25
+ [MeltwaterAttributes.COMPANYID]: companyId
26
+ });
27
27
 
28
28
  if (retries <= 3) {
29
29
  return this.getById(companyId, jwt, ++retries);
@@ -1,6 +1,7 @@
1
1
  import superagent from 'superagent'; // @todo remove superagent
2
2
  import logger from '../../lib/logger.js';
3
3
  import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
4
5
 
5
6
  export class CredentialsApiClient {
6
7
  constructor() {
@@ -39,8 +40,8 @@ export class CredentialsApiClient {
39
40
  userPermissionsEnabled
40
41
  ) {
41
42
  const loggerChild = logger.child({
42
- 'meltwater.company.id': companyId,
43
- 'user.id': userId,
43
+ [MeltwaterAttributes.COMPANYID]: companyId,
44
+ [MeltwaterAttributes.USERID]: userId,
44
45
  });
45
46
 
46
47
  let credentials;
@@ -88,8 +89,8 @@ export class CredentialsApiClient {
88
89
  // todo: will this need to ever use productArea?
89
90
  async getToken(credentialId, companyId) {
90
91
  const loggerChild = logger.child({
91
- 'meltwater.company.id': companyId,
92
- 'meltwater.social.credential_id': credentialId,
92
+ [MeltwaterAttributes.COMPANYID]: companyId,
93
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
93
94
  });
94
95
 
95
96
  let token;
@@ -1,6 +1,7 @@
1
1
  import superagent from 'superagent';
2
2
  import logger from '../../lib/logger.js';
3
3
  import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
4
5
 
5
6
  export class EntitlementsApiClient {
6
7
  constructor({ services }) {
@@ -11,7 +12,7 @@ export class EntitlementsApiClient {
11
12
 
12
13
  async getById(entitlementId, companyId, jwt, retries = 0) {
13
14
  const loggerChild = logger.child({
14
- 'meltwater.company.id': companyId,
15
+ [MeltwaterAttributes.COMPANYID]: companyId,
15
16
  });
16
17
 
17
18
  let entitlement;
@@ -2,6 +2,7 @@ import superagent from 'superagent'; // @todo remove superagent
2
2
  import logger from '../../lib/logger.js';
3
3
  import { removePrefix } from '../../lib/externalId.helpers.js';
4
4
  import { CredentialsApiClient } from '../http/credentialsApi.client.js';
5
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
5
6
 
6
7
  const FACEBOOK_URL = 'https://graph.facebook.com';
7
8
  export class FacebookApiClient {
@@ -37,14 +38,12 @@ export class FacebookApiClient {
37
38
  return response.body.shares && response.body.shares.count;
38
39
  } catch (error) {
39
40
  logger.error(
40
- `${documentId} - error recieved - ${error.code}`,
41
- error,
42
- {
43
- 'meltwater.document.id': documentId,
44
- 'meltwater.company.id': companyId,
45
- 'meltwater.social.credential_id': credentialId,
46
- }
47
- );
41
+ `${documentId} - error recieved - ${error.code}`, error, {
42
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
43
+ [MeltwaterAttributes.COMPANYID]: companyId,
44
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
45
+ });
46
+
48
47
  return undefined;
49
48
  }
50
49
  }
@@ -68,27 +67,24 @@ export class FacebookApiClient {
68
67
  `${FACEBOOK_URL}?ids=${documents
69
68
  .map((doc) => removePrefix(doc.metaData.externalId))
70
69
  .join(',')}&fields=` +
71
- `reactions.limit(0).summary(viewer_reaction).as(fb_post_reaction_of_user),` +
72
- `reactions.type(LOVE).limit(0).summary(total_count).as(fb_post_reactions_love),` +
73
- `reactions.type(WOW).limit(0).summary(total_count).as(fb_post_reactions_wow),` +
74
- `reactions.type(SAD).limit(0).summary(total_count).as(fb_post_reactions_sad),` +
75
- `reactions.type(LIKE).limit(0).summary(total_count).as(fb_post_reactions_like),` +
76
- `reactions.type(ANGRY).limit(0).summary(total_count).as(fb_post_reactions_angry),` +
77
- `reactions.type(HAHA).limit(0).summary(total_count).as(fb_post_reactions_haha)`,
70
+ `reactions.limit(0).summary(viewer_reaction).as(fb_post_reaction_of_user),` +
71
+ `reactions.type(LOVE).limit(0).summary(total_count).as(fb_post_reactions_love),` +
72
+ `reactions.type(WOW).limit(0).summary(total_count).as(fb_post_reactions_wow),` +
73
+ `reactions.type(SAD).limit(0).summary(total_count).as(fb_post_reactions_sad),` +
74
+ `reactions.type(LIKE).limit(0).summary(total_count).as(fb_post_reactions_like),` +
75
+ `reactions.type(ANGRY).limit(0).summary(total_count).as(fb_post_reactions_angry),` +
76
+ `reactions.type(HAHA).limit(0).summary(total_count).as(fb_post_reactions_haha)`,
78
77
  token.token,
79
78
  documentId
80
79
  );
81
80
  return response.body;
82
81
  } catch (error) {
83
82
  logger.error(
84
- `${documentId} - error recieved - ${error.code}`,
85
- error,
86
- {
87
- 'meltwater.document.id': documentId,
88
- 'meltwater.company.id': companyId,
89
- 'meltwater.social.credential_id': credentialId,
90
- }
91
- );
83
+ `${documentId} - error recieved - ${error.code}`, error, {
84
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
85
+ [MeltwaterAttributes.COMPANYID]: companyId,
86
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
87
+ });
92
88
  return undefined;
93
89
  }
94
90
  }
@@ -98,12 +94,12 @@ export class FacebookApiClient {
98
94
  const { inReplyToId, text, documentId, attachment } = payload;
99
95
  const isGif = attachment && attachment.mimeType === 'image/gif';
100
96
  const loggerChild = logger.child({
101
- 'meltwater.document.id': documentId,
97
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
102
98
  });
103
99
 
104
100
  loggerChild.debug(
105
101
  `Starting to call facebook comment api for documentId ${documentId}`,
106
- payload
102
+ { payload: JSON.stringify(payload) }
107
103
  );
108
104
 
109
105
  response = await this.postApi(
@@ -121,9 +117,9 @@ export class FacebookApiClient {
121
117
  loggerChild.info(
122
118
  `Native Facebook API Publish Comment Response for documentId ${documentId}`,
123
119
  {
124
- 'meltwater.document.id': documentId,
125
- status: response.status,
126
120
  ok: response.ok,
121
+ status: response.status,
122
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
127
123
  }
128
124
  );
129
125
  return response.body;
@@ -135,12 +131,12 @@ export class FacebookApiClient {
135
131
  payload;
136
132
  const isGif = attachment && attachment.mimeType === 'image/gif';
137
133
  const loggerChild = logger.child({
138
- 'meltwater.document.id': documentId,
134
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
139
135
  });
140
136
 
141
137
  loggerChild.debug(
142
138
  `Starting to call facebook messages api for documentId ${documentId}`,
143
- payload
139
+ { payload: JSON.stringify(payload) }
144
140
  );
145
141
 
146
142
  response = await this.postApi(
@@ -178,7 +174,7 @@ export class FacebookApiClient {
178
174
 
179
175
  async getApi(apiUrl, accessToken, documentId, payload, queryParams = {}) {
180
176
  const loggerChild = logger.child({
181
- 'meltwater.document.id': documentId,
177
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
182
178
  });
183
179
 
184
180
  let response = {};
@@ -210,7 +206,7 @@ export class FacebookApiClient {
210
206
  if (response.status !== 200) {
211
207
  loggerChild.error(
212
208
  `Failed to call facebook api for documentId ${documentId}`,
213
- response.body
209
+ { response: JSON.stringify(response.body) }
214
210
  );
215
211
  let error = new Error(
216
212
  `Failed to call facebook api for documentId ${documentId}`
@@ -225,7 +221,7 @@ export class FacebookApiClient {
225
221
  async postApi(apiUrl, accessToken, documentId, payload) {
226
222
  let response = {};
227
223
  const loggerChild = logger.child({
228
- 'meltwater.document.id': documentId,
224
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
229
225
  });
230
226
 
231
227
  try {
@@ -256,7 +252,7 @@ export class FacebookApiClient {
256
252
  if (response.status !== 200) {
257
253
  loggerChild.error(
258
254
  `Failed to call facebook api for documentId ${documentId}`,
259
- response.body
255
+ { response: JSON.stringify(response.body) }
260
256
  );
261
257
  let error = new Error(
262
258
  `Failed to call facebook api for documentId ${documentId}`
@@ -270,7 +266,7 @@ export class FacebookApiClient {
270
266
 
271
267
  async deleteApi(apiUrl, accessToken, documentId, payload) {
272
268
  const loggerChild = logger.child({
273
- 'meltwater.document.id': documentId,
269
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
274
270
  });
275
271
 
276
272
  let response = {};
@@ -302,7 +298,7 @@ export class FacebookApiClient {
302
298
  if (response.status !== 200) {
303
299
  loggerChild.error(
304
300
  `Failed to call facebook api for documentId ${documentId}`,
305
- response.body
301
+ { response: JSON.stringify(response.body) }
306
302
  );
307
303
  let error = new Error(
308
304
  `Failed to call facebook api for documentId ${documentId}`
@@ -332,9 +328,9 @@ export class FacebookApiClient {
332
328
  } = document;
333
329
 
334
330
  const loggerChild = logger.child({
335
- 'meltwater.document.id': documentId,
336
- 'meltwater.company.id': companyId,
337
- 'meltwater.social.credential_id': credentialId,
331
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
332
+ [MeltwaterAttributes.COMPANYID]: companyId,
333
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
338
334
  });
339
335
 
340
336
  let updatedDocument;
@@ -397,10 +393,7 @@ export class FacebookApiClient {
397
393
  );
398
394
  }
399
395
  } catch (exception) {
400
- loggerChild.error(
401
- documentId + ' - exception details ' + exception,
402
- exception
403
- );
396
+ loggerChild.error(`${documentId} - exception details`, exception);
404
397
  let findQuery = { documentId };
405
398
  findQuery['systemData.policies.storage.privateTo'] = companyId;
406
399
 
@@ -433,9 +426,9 @@ export class FacebookApiClient {
433
426
  let hideResponse;
434
427
 
435
428
  const loggerChild = logger.child({
436
- 'meltwater.document.id': documentId,
437
- 'meltwater.company.id': companyId,
438
- 'meltwater.social.credential_id': credentialId,
429
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
430
+ [MeltwaterAttributes.COMPANYID]: companyId,
431
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
439
432
  });
440
433
 
441
434
  try {
@@ -466,7 +459,7 @@ export class FacebookApiClient {
466
459
 
467
460
  loggerChild.debug(
468
461
  `finished hiding in facebook for ${documentId} on company ${companyId} `,
469
- { hideResponse }
462
+ { hideResponse: JSON.stringify(hideResponse) }
470
463
  );
471
464
 
472
465
  return hideResponse;
@@ -493,9 +486,9 @@ export class FacebookApiClient {
493
486
  } = document;
494
487
 
495
488
  const loggerChild = logger.child({
496
- 'meltwater.document.id': documentId,
497
- 'meltwater.company.id': companyId,
498
- 'meltwater.social.credential_id': credentialId,
489
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
490
+ [MeltwaterAttributes.COMPANYID]: companyId,
491
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
499
492
  });
500
493
 
501
494
  let banResponse;
@@ -529,7 +522,7 @@ export class FacebookApiClient {
529
522
 
530
523
  loggerChild.debug(
531
524
  `finished banning in facebook for ${authorId} on company ${companyId} `,
532
- { banResponse }
525
+ { banResponse: JSON.stringify(banResponse) }
533
526
  );
534
527
  } catch (error) {
535
528
  loggerChild.error(
@@ -553,9 +546,9 @@ export class FacebookApiClient {
553
546
  version,
554
547
  } = document;
555
548
  const loggerChild = logger.child({
556
- 'meltwater.document.id': documentId,
557
- 'meltwater.company.id': companyId,
558
- 'meltwater.social.credential_id': credentialId,
549
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
550
+ [MeltwaterAttributes.COMPANYID]: companyId,
551
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
559
552
  });
560
553
 
561
554
  try {
@@ -581,13 +574,10 @@ export class FacebookApiClient {
581
574
 
582
575
  loggerChild.debug(
583
576
  `finished liking in facebook for ${documentId} on company ${companyId} `,
584
- { likeResponse }
577
+ { likeResponse: JSON.stringify(likeResponse) }
585
578
  );
586
579
  } catch (error) {
587
- loggerChild.error(
588
- `${document} - error recieved - ${error.code}`,
589
- error
590
- );
580
+ loggerChild.error(`${document} - error recieved - ${error.code}`, error);
591
581
  throw error;
592
582
  }
593
583
  }
@@ -596,12 +586,12 @@ export class FacebookApiClient {
596
586
  let response;
597
587
  const { externalId, documentId } = command;
598
588
  const loggerChild = logger.child({
599
- 'meltwater.document.id': documentId,
589
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
600
590
  });
601
591
 
602
592
  loggerChild.debug(
603
593
  `Starting to call facebook like api for documentId ${documentId}`,
604
- { command }
594
+ { command: JSON.stringify(command) }
605
595
  );
606
596
 
607
597
  response = await this.postApi(
@@ -621,12 +611,12 @@ export class FacebookApiClient {
621
611
  let response;
622
612
  const { externalId, documentId } = command;
623
613
  const loggerChild = logger.child({
624
- 'meltwater.document.id': documentId,
614
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
625
615
  });
626
616
 
627
617
  loggerChild.debug(
628
618
  `Starting to call facebook unlike api for documentId ${documentId}`,
629
- command
619
+ { command: JSON.stringify(command) }
630
620
  );
631
621
 
632
622
  response = await this.deleteApi(
@@ -646,13 +636,13 @@ export class FacebookApiClient {
646
636
  let response;
647
637
  const { externalId, documentId } = command;
648
638
  const loggerChild = logger.child({
649
- 'meltwater.document.id': documentId,
650
- 'meltwater.document.external_id': externalId,
639
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
640
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId,
651
641
  });
652
642
 
653
643
  loggerChild.debug(
654
644
  `Starting to call facebook hide api for documentId ${documentId}`,
655
- { command }
645
+ { command: JSON.stringify(command) }
656
646
  );
657
647
 
658
648
  response = await this.postApi(
@@ -673,13 +663,13 @@ export class FacebookApiClient {
673
663
  let response;
674
664
  const { externalId, documentId } = command;
675
665
  const loggerChild = logger.child({
676
- 'meltwater.document.id': documentId,
677
- 'meltwater.document.external_id': externalId,
666
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
667
+ [MeltwaterAttributes.DOCUMENTEXTERNALID]: externalId,
678
668
  });
679
669
 
680
670
  loggerChild.debug(
681
671
  `Starting to call facebook unhide api for documentId ${documentId}`,
682
- command
672
+ { command: JSON.stringify(command) }
683
673
  );
684
674
 
685
675
  response = await this.postApi(
@@ -727,15 +717,14 @@ export class FacebookApiClient {
727
717
  }
728
718
 
729
719
  logger.info(
730
- `Native Facebook API is User Banned Response was invalid for userId ${userId} ${credentialId}`,
731
- { status: response.status, ok: response.ok },
732
- {
733
- 'meltwater.document.id': documentId,
734
- 'meltwater.social.credential_id': credentialId,
735
- 'meltwater.company.id': companyId,
736
- 'user.id': userId,
737
- }
738
- );
720
+ `Native Facebook API is User Banned Response was invalid for userId ${userId} ${credentialId}`, {
721
+ ok: response.ok,
722
+ status: response.status,
723
+ [MeltwaterAttributes.DOCUMENTID]: documentId,
724
+ [MeltwaterAttributes.CREDENTIALID]: credentialId,
725
+ [MeltwaterAttributes.COMPANYID]: companyId,
726
+ [MeltwaterAttributes.USERID]: userId,
727
+ });
739
728
 
740
729
  return false;
741
730
  }
@@ -746,7 +735,7 @@ export class FacebookApiClient {
746
735
 
747
736
  logger.debug(
748
737
  `Starting to call facebook ban api for externalAuthorId ${authorId}`,
749
- { command }
738
+ { command: JSON.stringify(command) }
750
739
  );
751
740
 
752
741
  response = await this.postApi(
@@ -769,7 +758,7 @@ export class FacebookApiClient {
769
758
 
770
759
  logger.debug(
771
760
  `Starting to call facebook unban api for externalAuthorId ${authorId}`,
772
- command
761
+ { command: JSON.stringify(command) }
773
762
  );
774
763
 
775
764
  response = await this.deleteApi(
@@ -1,6 +1,7 @@
1
1
  import superagent from 'superagent';
2
2
  import logger from '../../lib/logger.js';
3
3
  import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
4
5
 
5
6
  export class FeatureToggleClient {
6
7
  constructor() {
@@ -27,9 +28,9 @@ export class FeatureToggleClient {
27
28
  return result.body.treatments;
28
29
  } catch (error) {
29
30
  logger.error(
30
- `Failed requesting Feature Toggle service for feature toggle get `,
31
- { error, 'meltwater.company.id': companyId }
32
- );
31
+ `Failed requesting Feature Toggle service for feature toggle get `, error, {
32
+ [MeltwaterAttributes.COMPANYID]: companyId
33
+ });
33
34
  }
34
35
  }
35
36
  }
@@ -1,6 +1,7 @@
1
1
  import superagent from 'superagent';
2
2
  import logger from '../../lib/logger.js';
3
3
  import configuration from '../../lib/configuration.js';
4
+ import { MeltwaterAttributes } from '../../lib/logger.helpers.js';
4
5
 
5
6
  export class IdentityServicesClient {
6
7
  constructor({ companyId, services }) {
@@ -15,8 +16,8 @@ export class IdentityServicesClient {
15
16
  try {
16
17
  let resignedToken = await this.authService.getResignedToken(jwt);
17
18
  const loggerChild = logger.child({
18
- 'meltwater.user.id': userId,
19
- 'meltwater.company.id': this.companyId,
19
+ [MeltwaterAttributes.USERID]: userId,
20
+ [MeltwaterAttributes.COMPANYID]: this.companyId,
20
21
  });
21
22
 
22
23
  user = await superagent
@@ -46,7 +47,7 @@ export class IdentityServicesClient {
46
47
  async getAllUsers(jwt, retries = 0) {
47
48
  let users;
48
49
  const loggerChild = logger.child({
49
- 'meltwater.company.id': this.companyId,
50
+ [MeltwaterAttributes.COMPANYID]: this.companyId,
50
51
  });
51
52
 
52
53
  try {