@meltwater/conversations-api-services 1.0.1 → 1.0.3

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.1",
3
+ "version": "1.0.3",
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,7 +1,6 @@
1
1
  import { v4 } from 'uuid';
2
2
  import superagent from 'superagent';
3
3
  import logger from '../../lib/logger.js';
4
- import { awsSecrets } from './secrets.js';
5
4
  import configuration from '../../lib/configuration.js';
6
5
  import { metricN } from '../../lib/metrics.helper.js';
7
6
 
@@ -16,21 +15,19 @@ export class IRClient {
16
15
  }
17
16
 
18
17
  async init() {
19
- let irApiKey = process.env.IR_API_KEY
20
- ? { IR_API_KEY: process.env.IR_API_KEY }
21
- : await awsSecrets.getSecret('IR_API_KEY');
18
+ let irApiKey = configuration.get('IR_API_KEY');
22
19
 
23
20
  this.searchServicesUrl = configuration.get('SEARCH_SERVICE_URL');
24
- this.searchServicesKey = irApiKey.IR_API_KEY;
21
+ this.searchServicesKey = irApiKey;
25
22
 
26
23
  this.documentRevisionsServiceUrl = configuration.get(
27
24
  'DOCUMENT_REVISIONS_SERVICE_URL'
28
25
  );
29
26
  this.documentServiceUrl = configuration.get('DOCUMENT_SERVICE_URL');
30
- this.documentServiceKey = irApiKey.IR_API_KEY;
27
+ this.documentServiceKey = irApiKey;
31
28
 
32
29
  this.exportApiUrl = configuration.get('EXPORT_API_URL');
33
- this.exportApiKey = irApiKey.IR_API_KEY;
30
+ this.exportApiKey = irApiKey;
34
31
  }
35
32
 
36
33
  async addRevisionsToDocuments(operations) {
@@ -1,5 +1,5 @@
1
- import superagentfrom from 'superagent';
2
- import configurationfrom from '../../lib/configuration.js';
1
+ import superagent from 'superagent';
2
+ import configuration from '../../lib/configuration.js';
3
3
  // import { DOCUMENT_STATUS } from '@data-access/mongo/query.helpers.js';
4
4
  // import { messagesRepository } from '@data-access/mongo/repository/messages.js';
5
5
  // import PushRepositoryfrom from '@data-access/redis/repository/push.repository.js';
@@ -93,6 +93,65 @@ export class LinkedInApiClient {
93
93
  return response.connection || response;
94
94
  }
95
95
 
96
+ async deleteMessage(document) {
97
+ const {
98
+ documentId,
99
+ systemData: {
100
+ connectionsCredential: credentialId,
101
+ policies: {
102
+ storage: { privateTo: companyId },
103
+ },
104
+ },
105
+ metaData: {
106
+ externalId,
107
+ source: { id: actorURN },
108
+ inReplyTo: { id: inReplyToId },
109
+ },
110
+ } = document;
111
+
112
+ const [, comment] = externalId.split(',');
113
+ const commentId = comment.split(')')[0];
114
+
115
+ let response;
116
+ let query = `${configuration.get(
117
+ 'LINKEDIN_API'
118
+ )}/socialActions/${fixedEncodeURIComponent(
119
+ inReplyToId
120
+ )}/comments/${commentId}?actor=${fixedEncodeURIComponent(actorURN)}`;
121
+
122
+ try {
123
+ let credential = await this.tokenService.getByCredentialId(
124
+ credentialId,
125
+ companyId
126
+ );
127
+
128
+ this.logger.debug(`${documentId} - trying Delete `, {
129
+ query,
130
+ });
131
+ response = await superagent
132
+ .delete(query)
133
+ .timeout(5000)
134
+ .set({
135
+ Authorization: `Bearer ${credential.token}`,
136
+ 'X-RestLi-Protocol-Version': configuration.get(
137
+ 'LINKEDIN_API_VERSION'
138
+ ),
139
+ 'LinkedIn-Version': '202305',
140
+ });
141
+
142
+ this.logger.info(
143
+ `Native Linkedin API Delete Comment Response for documentId ${documentId}`,
144
+ { response }
145
+ );
146
+ } catch (err) {
147
+ this.logger.error(documentId + ' - exception details', {
148
+ err,
149
+ });
150
+ throw err;
151
+ }
152
+ return response;
153
+ }
154
+
96
155
  async publishComment(document, mediaId) {
97
156
  // command
98
157
  const {
@@ -1,7 +1,5 @@
1
1
  import { awsS3Client } from './http/amazonS3.js';
2
2
  import { assetManagerTvmRepository } from './http/asset-manager-tvm.client.js';
3
- import { assetManagerClient } from './http/asset-manager.client.js';
4
- import { awsSecrets } from './http/secrets.js';
5
3
  import { CompanyApiClient } from './http/companiesApi.client.js';
6
4
  import { CredentialsApiClient } from './http/credentialsApi.client.js';
7
5
  import { EntitlementsApiClient } from './http/entitlementsApi.client.js';
@@ -18,8 +16,6 @@ import { WarpZoneApiClient } from './http/WarpZoneApi.client.js';
18
16
  export {
19
17
  awsS3Client,
20
18
  assetManagerTvmRepository,
21
- assetManagerClient,
22
- awsSecrets,
23
19
  CompanyApiClient,
24
20
  CredentialsApiClient,
25
21
  EntitlementsApiClient,
@@ -1,164 +0,0 @@
1
- import superagent from 'superagent';
2
- import logger from '../../lib/logger.js';
3
- import { generateToken } from '../../lib/auth.helpers.js';
4
-
5
- class AssetManagerClient {
6
- apiKey;
7
- constructor() {
8
- const { GRAPHQL_GATEWAY_URL } = process.env;
9
- this.gatewayURL = GRAPHQL_GATEWAY_URL;
10
- this.request = superagent;
11
- }
12
-
13
- /**
14
- *
15
- * @param {*} assetQuery
16
- * @param {*} assetQuery.assetId
17
- * @param {*} assetQuery.userId
18
- * @param {*} assetQuery.companyId
19
- * @returns
20
- */
21
- async getURL({ assetId, userId, companyId }) {
22
- try {
23
- const response = await this.request
24
- .post(`${this.gatewayURL}`)
25
- .set('apollographql-client-name', 'phoenix-conversations')
26
- .set('Authorization', await generateToken(userId, companyId))
27
- .send({
28
- query: `
29
- query getAssetUrlForPublishing(
30
- $filter: AssetFilterInput
31
- ) {
32
- assets(filter: $filter) {
33
- edges {
34
- node {
35
- url
36
- }
37
- }
38
- }
39
- }
40
- `,
41
- operationName: 'getAssetUrlForPublishing',
42
- variables: {
43
- filter: {
44
- ids: [assetId],
45
- uploadPath: [
46
- 'ASSET_MANAGER',
47
- 'ENGAGE_CONVERSATIONS',
48
- ],
49
- },
50
- },
51
- });
52
- return response.body;
53
- } catch (exception) {
54
- // How would you prefer to handle this
55
- logger.error('Error getting asset url', {
56
- assetId,
57
- userId,
58
- companyId,
59
- exception,
60
- });
61
- throw exception;
62
- }
63
- }
64
-
65
- async getAssetUrlAndSize({ assetId, userId, companyId }) {
66
- try {
67
- const response = await this.request
68
- .post(`${this.gatewayURL}`)
69
- .set('apollographql-client-name', 'grimoire-publisher')
70
- .set('Authorization', await generateToken(userId, companyId))
71
- .send({
72
- query: `
73
- query getAssetUrlAndSizeForPublishing(
74
- $filter: AssetFilterInput
75
- ) {
76
- assets(filter: $filter) {
77
- edges {
78
- node {
79
- url
80
- size {
81
- bytes
82
- }
83
- }
84
- }
85
- }
86
- }
87
- `,
88
- operationName: 'getAssetUrlAndSizeForPublishing',
89
- variables: {
90
- filter: {
91
- ids: [assetId],
92
- uploadPath: [
93
- 'ASSET_MANAGER',
94
- 'ENGAGE_CONVERSATIONS',
95
- ],
96
- },
97
- },
98
- });
99
- return response.body;
100
- } catch (exception) {
101
- // How would you prefer to handle this
102
- logger.error('Error getting asset', {
103
- assetId,
104
- userId,
105
- companyId,
106
- exception,
107
- });
108
- throw exception;
109
- }
110
- }
111
-
112
- async getAsset({ assetId, userId, companyId }) {
113
- try {
114
- const response = await this.request
115
- .post(`${this.gatewayURL}`)
116
- .set('apollographql-client-name', 'grimoire-publisher')
117
- .set('Authorization', await generateToken(userId, companyId))
118
- .send({
119
- query: `
120
- query getAssetUrlAndSizeForPublishing(
121
- $filter: AssetFilterInput
122
- ) {
123
- assets(filter: $filter) {
124
- edges {
125
- node {
126
- fileName
127
- url
128
- size {
129
- bytes
130
- }
131
- path
132
- type
133
- mimeType
134
- }
135
- }
136
- }
137
- }
138
- `,
139
- operationName: 'getAssetUrlAndSizeForPublishing',
140
- variables: {
141
- filter: {
142
- ids: [assetId],
143
- uploadPath: [
144
- 'ASSET_MANAGER',
145
- 'ENGAGE_CONVERSATIONS',
146
- ],
147
- },
148
- },
149
- });
150
- return response.body;
151
- } catch (exception) {
152
- // How would you prefer to handle this
153
- logger.error('Error getting asset', {
154
- assetId,
155
- userId,
156
- companyId,
157
- exception,
158
- });
159
- throw exception;
160
- }
161
- }
162
- }
163
-
164
- export const assetManagerClient = new AssetManagerClient();
@@ -1,55 +0,0 @@
1
- import logger from '../../lib/logger.js';
2
- import AWS from 'aws-sdk';
3
-
4
- class AWS_Secrets {
5
- constructor() {
6
- const secrets = [
7
- 'TWITTER_APP_INFO',
8
- 'IR_API_KEY',
9
- 'CONVERSATIONS_API_IDENTITY',
10
- 'SES_ACCESS_KEY',
11
- ];
12
-
13
- if (process.env.AWS_ACCESS_KEY_ID_SECRETS) {
14
- AWS.config.update({
15
- accessKeyId: process.env.AWS_ACCESS_KEY_ID_SECRETS,
16
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_SECRETS,
17
- region: process.env.AWS_DEFAULT_REGION || 'eu-west-1',
18
- });
19
- } else {
20
- AWS.config.update({
21
- region: process.env.AWS_DEFAULT_REGION || 'eu-west-1',
22
- });
23
- }
24
-
25
- const client = new AWS.SecretsManager({ apiVersion: '2017-10-17' });
26
- this.secretsLookup = secrets.reduce((secretsLookupPromise, secret) => {
27
- return secretsLookupPromise.then((lookup) => {
28
- return client
29
- .getSecretValue({ SecretId: secret })
30
- .promise()
31
- .then((data) => {
32
- if (data.SecretString) {
33
- lookup[secret] = JSON.parse(data.SecretString);
34
- }
35
-
36
- return lookup;
37
- })
38
- .catch((error) => {
39
- logger.error('Error Getting Secret Values', {
40
- secret,
41
- error,
42
- });
43
-
44
- return lookup;
45
- });
46
- });
47
- }, Promise.resolve({}));
48
- }
49
-
50
- async getSecret(secret) {
51
- return (await this.secretsLookup)[secret];
52
- }
53
- }
54
-
55
- export const awsSecrets = new AWS_Secrets();
@@ -1,34 +0,0 @@
1
- import jwt from 'jsonwebtoken';
2
- import { awsSecrets } from '../data-access/http/secrets.js';
3
- import configuration from '../lib/configuration.js';
4
-
5
- export async function generateToken(userId, companyId, expiresIn = '5m') {
6
- this.privateKey = await awsSecrets
7
- .getSecret('CONVERSATIONS_API_IDENTITY')
8
- .then((privateKey) => {
9
- return Buffer.from(
10
- privateKey.CONVERSATIONS_API_IDENTITY,
11
- 'base64'
12
- ).toString('ascii');
13
- });
14
-
15
- const token = jwt.sign(
16
- {
17
- user: {
18
- _id: userId,
19
- email: 'all.phoenix@meltwater.com',
20
- },
21
- company: {
22
- _id: companyId,
23
- },
24
- },
25
- `${privateKey}`,
26
- {
27
- algorithm: 'RS256',
28
- keyid: `${configuration.get('JWKS_IDENTITY_KID')}`,
29
- expiresIn,
30
- }
31
- );
32
-
33
- return token;
34
- }