@meltwater/conversations-api-services 1.0.7 → 1.0.9

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.
@@ -0,0 +1,40 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ permissions:
8
+ contents: read # for checkout
9
+
10
+ jobs:
11
+ release:
12
+ name: Release
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: write # to be able to publish a GitHub release
16
+ issues: write # to be able to comment on released issues
17
+ pull-requests: write # to be able to comment on released pull requests
18
+ id-token: write # to enable use of OIDC for npm provenance
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v3
22
+ with:
23
+ fetch-depth: 0
24
+ persist-credential: false
25
+ token: ${{ secrets.GH_TOKEN }}
26
+ - name: Setup Node.js
27
+ uses: actions/setup-node@v3
28
+ with:
29
+ node-version: "lts/*"
30
+ - name: NPM Auth Setup
31
+ run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
32
+ - name: Install dependencies
33
+ run: npm clean-install
34
+ - name: Verify signatures
35
+ run: npm audit signatures
36
+ - name: Release
37
+ env:
38
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
40
+ run: npx semantic-release
package/README.md CHANGED
@@ -2,41 +2,10 @@
2
2
 
3
3
  Repository to contain all conversations api services shared across our services
4
4
 
5
- ---
6
-
7
- This section should answer:
8
-
9
- > What is this?
10
-
11
- Adding visuals to this project description will make your project more memorable and the README easier to understand.
12
-
13
- Great examples:
14
-
15
- - [meltwater/contact-source-service](https://github.com/meltwater/contact-source-service) - _It is the backend behind the Influencers application used by Meltwater customers. It provides sources/contacts management and search capabilities._
16
- - [release-it/release-it](https://github.com/release-it/release-it) - _‌Generic CLI tool to automate versioning and package publishing related tasks_
17
-
18
- ## Product / Business Purpose
19
-
20
- An explanation of the business purpose of this repo, e.g. the Meltwater Product that this ties into. This section should answer:
21
-
22
- > Why does this exist?
23
-
24
- Great examples:
25
-
26
- - [meltwater/chat-message-integration](https://github.com/meltwater/chat-message-integration) _The chat-message-integration project is the API that is used to configure and handle messages for Slack and Teams integrations in the MI App._
27
- - [meltwater/explore-compare-service](https://github.com/meltwater/explore-compare-service) - _Compares in Explorer allow users to run several saved queries at the same time and do a comparison._
28
-
29
5
  ## Maintainers
30
6
 
31
- Meltwater's current ownership model assumes that every piece of software running in Production is owned by a team. This section should answer:
32
-
33
- > Who owns this?
34
- > Who to contact for help?
35
-
36
- Example:
37
-
38
- > Maintained by TEAM_NAME (TEAM_EMAIL_ADDRESS@meltwater.com).
39
- > Contact us via #TEAM_SLACK_CHANNEL in Slack.
7
+ > Maintained by Phoenix (phoenix@meltwater.com).
8
+ > Contact us via #eng-team-phoenix in Slack.
40
9
 
41
10
  ## Contributing
42
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
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",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "homepage": "https://github.com/meltwater/conversations-api-services#readme",
25
25
  "dependencies": {
26
+ "@elastic/ecs-winston-format": "^1.5.3",
26
27
  "@hapi/joi": "^17.1.1",
27
28
  "@meltwater/date-range": "^3.6.0",
28
29
  "@meltwater/engage-conversations-schemas": "^2.3.10",
@@ -21,7 +21,7 @@ class AssetManagerTVMRepository {
21
21
  })
22
22
  .then((result) => result.body);
23
23
  } catch (error) {
24
- logger.error(error);
24
+ logger.error(error, { 'meltwater.company.id': companyId });
25
25
  throw error;
26
26
  }
27
27
 
@@ -21,7 +21,8 @@ export class CompanyApiClient {
21
21
  } catch (error) {
22
22
  logger.error(
23
23
  `Failed requesting Companies Api for companyId ${companyId} retry ${retries}`,
24
- error
24
+ error,
25
+ { 'meltwater.company.id': companyId }
25
26
  );
26
27
 
27
28
  if (retries <= 3) {
@@ -38,10 +38,15 @@ export class CredentialsApiClient {
38
38
  { companyId, userId, productArea },
39
39
  userPermissionsEnabled
40
40
  ) {
41
+ const loggerChild = logger.child({
42
+ 'meltwater.company.id': companyId,
43
+ 'user.id': userId,
44
+ });
45
+
41
46
  let credentials;
42
47
  try {
43
48
  if (productArea) {
44
- logger.info(
49
+ loggerChild.info(
45
50
  `Get Credentials for company: ${companyId} and user: ${userId}`
46
51
  );
47
52
  credentials = await superagent
@@ -66,14 +71,14 @@ export class CredentialsApiClient {
66
71
  .then((result) => result.body.data);
67
72
  }
68
73
  } catch (error) {
69
- logger.error(
74
+ loggerChild.error(
70
75
  `Failed requesting Credentials API for companyId ${companyId} ${userId}`,
71
76
  error
72
77
  );
73
78
  return [];
74
79
  }
75
80
 
76
- logger.info(
81
+ loggerChild.info(
77
82
  `Finished requesting Credentials API for companyId ${companyId}`
78
83
  );
79
84
 
@@ -82,6 +87,11 @@ export class CredentialsApiClient {
82
87
 
83
88
  // todo: will this need to ever use productArea?
84
89
  async getToken(credentialId, companyId) {
90
+ const loggerChild = logger.child({
91
+ 'meltwater.company.id': companyId,
92
+ 'meltwater.social.credential_id': credentialId,
93
+ });
94
+
85
95
  let token;
86
96
  try {
87
97
  token = await superagent
@@ -92,14 +102,14 @@ export class CredentialsApiClient {
92
102
  return result.body;
93
103
  });
94
104
  } catch (error) {
95
- logger.error(
105
+ loggerChild.error(
96
106
  `Failed requesting Credentials API for credentialId ${credentialId} and companyId ${companyId}`,
97
107
  error
98
108
  );
99
109
  return;
100
110
  }
101
111
 
102
- logger.info(
112
+ loggerChild.info(
103
113
  `Finished requesting Credentials API for credentialId ${credentialId} and companyId ${companyId}`
104
114
  );
105
115
 
@@ -10,6 +10,10 @@ export class EntitlementsApiClient {
10
10
  }
11
11
 
12
12
  async getById(entitlementId, companyId, jwt, retries = 0) {
13
+ const loggerChild = logger.child({
14
+ 'meltwater.company.id': companyId,
15
+ });
16
+
13
17
  let entitlement;
14
18
  try {
15
19
  let resignedToken = await this.authService.getResignedToken(jwt);
@@ -21,7 +25,7 @@ export class EntitlementsApiClient {
21
25
  .set('x-client-name', configuration.get('CLIENT_NAME_HEADER'))
22
26
  .then((result) => result.body);
23
27
  } catch (error) {
24
- logger.error(
28
+ loggerChild.error(
25
29
  `Failed requesting entitlement ${entitlementId} for companyId ${companyId} retry ${retries}`,
26
30
  error
27
31
  );
@@ -32,7 +36,7 @@ export class EntitlementsApiClient {
32
36
  return;
33
37
  }
34
38
 
35
- logger.info(
39
+ loggerChild.info(
36
40
  `Finished requesting entitlement ${entitlementId} for companyId ${companyId}`
37
41
  );
38
42
 
@@ -38,7 +38,12 @@ export class FacebookApiClient {
38
38
  } catch (error) {
39
39
  logger.error(
40
40
  `${documentId} - error recieved - ${error.code}`,
41
- error
41
+ error,
42
+ {
43
+ 'meltwater.document.id': documentId,
44
+ 'meltwater.company.id': companyId,
45
+ 'meltwater.social.credential_id': credentialId,
46
+ }
42
47
  );
43
48
  return undefined;
44
49
  }
@@ -77,7 +82,12 @@ export class FacebookApiClient {
77
82
  } catch (error) {
78
83
  logger.error(
79
84
  `${documentId} - error recieved - ${error.code}`,
80
- error
85
+ error,
86
+ {
87
+ 'meltwater.document.id': documentId,
88
+ 'meltwater.company.id': companyId,
89
+ 'meltwater.social.credential_id': credentialId,
90
+ }
81
91
  );
82
92
  return undefined;
83
93
  }
@@ -87,8 +97,11 @@ export class FacebookApiClient {
87
97
  let response;
88
98
  const { inReplyToId, text, documentId, attachment } = payload;
89
99
  const isGif = attachment && attachment.mimeType === 'image/gif';
100
+ const loggerChild = logger.child({
101
+ 'meltwater.document.id': documentId,
102
+ });
90
103
 
91
- logger.debug(
104
+ loggerChild.debug(
92
105
  `Starting to call facebook comment api for documentId ${documentId}`,
93
106
  payload
94
107
  );
@@ -105,9 +118,13 @@ export class FacebookApiClient {
105
118
  isGif && { attachment_share_url: attachment.link }),
106
119
  }
107
120
  );
108
- logger.info(
121
+ loggerChild.info(
109
122
  `Native Facebook API Publish Comment Response for documentId ${documentId}`,
110
- { status: response.status, ok: response.ok }
123
+ {
124
+ 'meltwater.document.id': documentId,
125
+ status: response.status,
126
+ ok: response.ok,
127
+ }
111
128
  );
112
129
  return response.body;
113
130
  }
@@ -117,7 +134,11 @@ export class FacebookApiClient {
117
134
  const { profileId, recipientId, text, documentId, attachment } =
118
135
  payload;
119
136
  const isGif = attachment && attachment.mimeType === 'image/gif';
120
- logger.debug(
137
+ const loggerChild = logger.child({
138
+ 'meltwater.document.id': documentId,
139
+ });
140
+
141
+ loggerChild.debug(
121
142
  `Starting to call facebook messages api for documentId ${documentId}`,
122
143
  payload
123
144
  );
@@ -145,14 +166,21 @@ export class FacebookApiClient {
145
166
  tag: 'HUMAN_AGENT',
146
167
  }
147
168
  );
148
- logger.info(
169
+ loggerChild.info(
149
170
  `Native Facebook API Publish Private Message Response for documentId ${documentId}`,
150
- { status: response.status, ok: response.ok }
171
+ {
172
+ status: response.status,
173
+ ok: response.ok,
174
+ }
151
175
  );
152
176
  return response.body;
153
177
  }
154
178
 
155
179
  async getApi(apiUrl, accessToken, documentId, payload, queryParams = {}) {
180
+ const loggerChild = logger.child({
181
+ 'meltwater.document.id': documentId,
182
+ });
183
+
156
184
  let response = {};
157
185
  try {
158
186
  response = await superagent
@@ -170,17 +198,17 @@ export class FacebookApiClient {
170
198
  err.response.body.error
171
199
  ) {
172
200
  errorText = `Failed to call facebook api for documentId ${documentId}: ${err.response.body.error.message}`;
173
- logger.error(errorText);
201
+ loggerChild.error(errorText);
174
202
  } else {
175
203
  errorText = `Failed to call facebook api for documentId ${documentId}`;
176
- logger.error(errorText, err);
204
+ loggerChild.error(errorText, err);
177
205
  }
178
206
 
179
207
  throw new Error(errorText);
180
208
  }
181
209
 
182
210
  if (response.status !== 200) {
183
- logger.error(
211
+ loggerChild.error(
184
212
  `Failed to call facebook api for documentId ${documentId}`,
185
213
  response.body
186
214
  );
@@ -196,6 +224,10 @@ export class FacebookApiClient {
196
224
 
197
225
  async postApi(apiUrl, accessToken, documentId, payload) {
198
226
  let response = {};
227
+ const loggerChild = logger.child({
228
+ 'meltwater.document.id': documentId,
229
+ });
230
+
199
231
  try {
200
232
  response = await superagent
201
233
  .post(apiUrl)
@@ -212,17 +244,17 @@ export class FacebookApiClient {
212
244
  err.response.body.error
213
245
  ) {
214
246
  errorText = `Failed to call facebook api for documentId ${documentId}: ${err.response.body.error.message}`;
215
- logger.error(errorText);
247
+ loggerChild.error(errorText);
216
248
  } else {
217
249
  errorText = `Failed to call facebook api for documentId ${documentId}`;
218
- logger.error(errorText, err);
250
+ loggerChild.error(errorText, err);
219
251
  }
220
252
 
221
253
  throw new Error(errorText);
222
254
  }
223
255
 
224
256
  if (response.status !== 200) {
225
- logger.error(
257
+ loggerChild.error(
226
258
  `Failed to call facebook api for documentId ${documentId}`,
227
259
  response.body
228
260
  );
@@ -237,6 +269,10 @@ export class FacebookApiClient {
237
269
  }
238
270
 
239
271
  async deleteApi(apiUrl, accessToken, documentId, payload) {
272
+ const loggerChild = logger.child({
273
+ 'meltwater.document.id': documentId,
274
+ });
275
+
240
276
  let response = {};
241
277
  try {
242
278
  response = await superagent
@@ -254,17 +290,17 @@ export class FacebookApiClient {
254
290
  err.response.body.error
255
291
  ) {
256
292
  errorText = `Failed to call facebook api for documentId ${documentId}: ${err.response.body.error.message}`;
257
- logger.error(errorText);
293
+ loggerChild.error(errorText);
258
294
  } else {
259
295
  errorText = `Failed to call facebook api for documentId ${documentId}`;
260
- logger.error(errorText, err);
296
+ loggerChild.error(errorText, err);
261
297
  }
262
298
 
263
299
  throw new Error(errorText);
264
300
  }
265
301
 
266
302
  if (response.status !== 200) {
267
- logger.error(
303
+ loggerChild.error(
268
304
  `Failed to call facebook api for documentId ${documentId}`,
269
305
  response.body
270
306
  );
@@ -295,6 +331,12 @@ export class FacebookApiClient {
295
331
  } = {},
296
332
  } = document;
297
333
 
334
+ const loggerChild = logger.child({
335
+ 'meltwater.document.id': documentId,
336
+ 'meltwater.company.id': companyId,
337
+ 'meltwater.social.credential_id': credentialId,
338
+ });
339
+
298
340
  let updatedDocument;
299
341
  let apiResponse;
300
342
  try {
@@ -302,8 +344,8 @@ export class FacebookApiClient {
302
344
  credentialId,
303
345
  companyId
304
346
  );
305
- logger.debug(
306
- `finished fetching token for Facebook for ${documentId} on company ${companyId} `
347
+ loggerChild.debug(
348
+ `finished fetching token for Facebook for ${documentId} on company ${companyId}`
307
349
  );
308
350
  let payload;
309
351
  switch (discussionType) {
@@ -355,7 +397,7 @@ export class FacebookApiClient {
355
397
  );
356
398
  }
357
399
  } catch (exception) {
358
- logger.error(
400
+ loggerChild.error(
359
401
  documentId + ' - exception details ' + exception,
360
402
  exception
361
403
  );
@@ -390,8 +432,14 @@ export class FacebookApiClient {
390
432
  } = document;
391
433
  let hideResponse;
392
434
 
435
+ const loggerChild = logger.child({
436
+ 'meltwater.document.id': documentId,
437
+ 'meltwater.company.id': companyId,
438
+ 'meltwater.social.credential_id': credentialId,
439
+ });
440
+
393
441
  try {
394
- logger.debug(
442
+ loggerChild.debug(
395
443
  `processing Facebook Version ${version} for documentID ${documentId} on company ${companyId}`
396
444
  );
397
445
 
@@ -400,7 +448,7 @@ export class FacebookApiClient {
400
448
  companyId
401
449
  );
402
450
 
403
- logger.debug(
451
+ loggerChild.debug(
404
452
  `finished fetching token for facebook for ${documentId} on company ${companyId} `
405
453
  );
406
454
 
@@ -416,14 +464,14 @@ export class FacebookApiClient {
416
464
  });
417
465
  }
418
466
 
419
- logger.debug(
467
+ loggerChild.debug(
420
468
  `finished hiding in facebook for ${documentId} on company ${companyId} `,
421
469
  { hideResponse }
422
470
  );
423
471
 
424
472
  return hideResponse;
425
473
  } catch (error) {
426
- logger.error(
474
+ loggerChild.error(
427
475
  `${documentId} - error recieved - ${error.code}`,
428
476
  error
429
477
  );
@@ -444,11 +492,17 @@ export class FacebookApiClient {
444
492
  version,
445
493
  } = document;
446
494
 
495
+ const loggerChild = logger.child({
496
+ 'meltwater.document.id': documentId,
497
+ 'meltwater.company.id': companyId,
498
+ 'meltwater.social.credential_id': credentialId,
499
+ });
500
+
447
501
  let banResponse;
448
502
  let authorId = authors[0].authorInfo.externalId;
449
503
 
450
504
  try {
451
- logger.debug(
505
+ loggerChild.debug(
452
506
  `processing Facebook Version ${version} for profileId ${authorId} on company ${companyId}`
453
507
  );
454
508
 
@@ -457,7 +511,7 @@ export class FacebookApiClient {
457
511
  companyId
458
512
  );
459
513
 
460
- logger.debug(
514
+ loggerChild.debug(
461
515
  `finished fetching token for facebook for ${authorId} on company ${companyId} `
462
516
  );
463
517
 
@@ -473,12 +527,15 @@ export class FacebookApiClient {
473
527
  });
474
528
  }
475
529
 
476
- logger.debug(
530
+ loggerChild.debug(
477
531
  `finished banning in facebook for ${authorId} on company ${companyId} `,
478
532
  { banResponse }
479
533
  );
480
534
  } catch (error) {
481
- logger.error(`${authorId} - error recieved - ${error.code}`, error);
535
+ loggerChild.error(
536
+ `${authorId} - error recieved - ${error.code}`,
537
+ error
538
+ );
482
539
  }
483
540
  }
484
541
 
@@ -495,13 +552,18 @@ export class FacebookApiClient {
495
552
  } = {},
496
553
  version,
497
554
  } = document;
555
+ const loggerChild = logger.child({
556
+ 'meltwater.document.id': documentId,
557
+ 'meltwater.company.id': companyId,
558
+ 'meltwater.social.credential_id': credentialId,
559
+ });
498
560
 
499
561
  try {
500
- logger.debug(
562
+ loggerChild.debug(
501
563
  `processing Facebook Version ${version} for documentID ${documentId}`
502
564
  );
503
565
 
504
- logger.debug(
566
+ loggerChild.debug(
505
567
  `starting to fetch tokens for facebook for ${documentId} on company ${companyId} `
506
568
  );
507
569
  const token = await this.credentialsAPI.getToken(
@@ -509,7 +571,7 @@ export class FacebookApiClient {
509
571
  companyId
510
572
  );
511
573
 
512
- logger.debug(
574
+ loggerChild.debug(
513
575
  `finished fetching token for facebook for ${documentId} on company ${companyId} `
514
576
  );
515
577
 
@@ -517,12 +579,15 @@ export class FacebookApiClient {
517
579
  ? this.like(token, { externalId, documentId })
518
580
  : this.unlike(token, { externalId, documentId }));
519
581
 
520
- logger.debug(
582
+ loggerChild.debug(
521
583
  `finished liking in facebook for ${documentId} on company ${companyId} `,
522
584
  { likeResponse }
523
585
  );
524
586
  } catch (error) {
525
- logger.error(`${document} - error recieved - ${error.code}`, error);
587
+ loggerChild.error(
588
+ `${document} - error recieved - ${error.code}`,
589
+ error
590
+ );
526
591
  throw error;
527
592
  }
528
593
  }
@@ -530,8 +595,11 @@ export class FacebookApiClient {
530
595
  async like(accessToken, command) {
531
596
  let response;
532
597
  const { externalId, documentId } = command;
598
+ const loggerChild = logger.child({
599
+ 'meltwater.document.id': documentId,
600
+ });
533
601
 
534
- logger.debug(
602
+ loggerChild.debug(
535
603
  `Starting to call facebook like api for documentId ${documentId}`,
536
604
  { command }
537
605
  );
@@ -542,7 +610,7 @@ export class FacebookApiClient {
542
610
  documentId
543
611
  );
544
612
 
545
- logger.info(
613
+ loggerChild.info(
546
614
  `Native Facebook API Like Response for documentId ${documentId}`,
547
615
  { status: response.status, ok: response.ok }
548
616
  );
@@ -552,8 +620,11 @@ export class FacebookApiClient {
552
620
  async unlike(accessToken, command) {
553
621
  let response;
554
622
  const { externalId, documentId } = command;
623
+ const loggerChild = logger.child({
624
+ 'meltwater.document.id': documentId,
625
+ });
555
626
 
556
- logger.debug(
627
+ loggerChild.debug(
557
628
  `Starting to call facebook unlike api for documentId ${documentId}`,
558
629
  command
559
630
  );
@@ -564,7 +635,7 @@ export class FacebookApiClient {
564
635
  documentId
565
636
  );
566
637
 
567
- logger.info(
638
+ loggerChild.info(
568
639
  `Native Facebook API Unlike Response for documentId ${documentId}`,
569
640
  { status: response.status, ok: response.ok }
570
641
  );
@@ -574,8 +645,12 @@ export class FacebookApiClient {
574
645
  async hide(accessToken, command) {
575
646
  let response;
576
647
  const { externalId, documentId } = command;
648
+ const loggerChild = logger.child({
649
+ 'meltwater.document.id': documentId,
650
+ 'meltwater.document.external_id': externalId,
651
+ });
577
652
 
578
- logger.debug(
653
+ loggerChild.debug(
579
654
  `Starting to call facebook hide api for documentId ${documentId}`,
580
655
  { command }
581
656
  );
@@ -587,7 +662,7 @@ export class FacebookApiClient {
587
662
  { is_hidden: true }
588
663
  );
589
664
 
590
- logger.info(
665
+ loggerChild.info(
591
666
  `Native Facebook API Hide Response for documentId ${documentId}`,
592
667
  { status: response.status, ok: response.ok }
593
668
  );
@@ -597,8 +672,12 @@ export class FacebookApiClient {
597
672
  async unhide(accessToken, command) {
598
673
  let response;
599
674
  const { externalId, documentId } = command;
675
+ const loggerChild = logger.child({
676
+ 'meltwater.document.id': documentId,
677
+ 'meltwater.document.external_id': externalId,
678
+ });
600
679
 
601
- logger.debug(
680
+ loggerChild.debug(
602
681
  `Starting to call facebook unhide api for documentId ${documentId}`,
603
682
  command
604
683
  );
@@ -610,7 +689,7 @@ export class FacebookApiClient {
610
689
  { is_hidden: false }
611
690
  );
612
691
 
613
- logger.info(
692
+ loggerChild.info(
614
693
  `Native Facebook API Unhide Response for documentId ${documentId}`,
615
694
  { status: response.status, ok: response.ok }
616
695
  );
@@ -646,10 +725,18 @@ export class FacebookApiClient {
646
725
  return false;
647
726
  }
648
727
  }
728
+
649
729
  logger.info(
650
730
  `Native Facebook API is User Banned Response was invalid for userId ${userId} ${credentialId}`,
651
- { status: response.status, ok: response.ok }
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
+ }
652
738
  );
739
+
653
740
  return false;
654
741
  }
655
742
 
@@ -28,7 +28,7 @@ export class FeatureToggleClient {
28
28
  } catch (error) {
29
29
  logger.error(
30
30
  `Failed requesting Feature Toggle service for feature toggle get `,
31
- { error, companyId }
31
+ { error, 'meltwater.company.id': companyId }
32
32
  );
33
33
  }
34
34
  }