@meltwater/conversations-api-services 1.3.2 → 1.4.0
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/.github/workflows/release.yml +4 -6
- package/CLAUDE.md +70 -0
- package/dist/cjs/data-access/http/facebook.native.js +122 -106
- package/dist/cjs/data-access/http/instagram.native.js +92 -49
- package/dist/cjs/data-access/http/linkedin.native.js +135 -56
- package/dist/cjs/data-access/http/threads.native.js +53 -18
- package/dist/cjs/data-access/http/tiktok.native.js +18 -12
- package/dist/cjs/data-access/http/twitter.native.js +142 -40
- package/dist/cjs/data-access/http/youtube.native.js +19 -13
- package/dist/esm/data-access/http/facebook.native.js +123 -107
- package/dist/esm/data-access/http/instagram.native.js +93 -50
- package/dist/esm/data-access/http/linkedin.native.js +136 -57
- package/dist/esm/data-access/http/threads.native.js +54 -19
- package/dist/esm/data-access/http/tiktok.native.js +19 -13
- package/dist/esm/data-access/http/twitter.native.js +143 -41
- package/dist/esm/data-access/http/youtube.native.js +20 -14
- package/package.json +1 -3
- package/src/data-access/http/README.md +50 -0
- package/src/data-access/http/facebook.native.js +122 -144
- package/src/data-access/http/instagram.native.js +113 -93
- package/src/data-access/http/linkedin.native.js +144 -83
- package/src/data-access/http/threads.native.js +58 -27
- package/src/data-access/http/tiktok.native.js +19 -39
- package/src/data-access/http/twitter.native.js +145 -65
- package/src/data-access/http/youtube.native.js +21 -40
- package/dist/cjs/lib/hiddenComment.helper.js +0 -119
- package/dist/esm/lib/hiddenComment.helper.js +0 -112
- package/src/lib/hiddenComment.helper.js +0 -107
|
@@ -2,9 +2,9 @@ import superagent from 'superagent';
|
|
|
2
2
|
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
3
|
import {
|
|
4
4
|
loggerDebug,
|
|
5
|
-
loggerError,
|
|
6
5
|
loggerInfo,
|
|
7
6
|
loggerWarn,
|
|
7
|
+
MeltwaterAttributes,
|
|
8
8
|
} from '../../lib/logger.helpers.js';
|
|
9
9
|
import OAuth from 'oauth-1.0a';
|
|
10
10
|
import crypto from 'crypto';
|
|
@@ -88,10 +88,15 @@ async function makeTwitterV2Request(
|
|
|
88
88
|
source: 'v1.1',
|
|
89
89
|
};
|
|
90
90
|
} catch (fallbackError) {
|
|
91
|
-
|
|
91
|
+
loggerInfo(
|
|
92
92
|
logger,
|
|
93
|
-
`
|
|
94
|
-
|
|
93
|
+
`Failed to call twitter api - makeTwitterV2Request`,
|
|
94
|
+
{
|
|
95
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
96
|
+
v2Endpoint,
|
|
97
|
+
error: fallbackError?.message,
|
|
98
|
+
}),
|
|
99
|
+
}
|
|
95
100
|
);
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -141,17 +146,25 @@ function normalizeUsersData(users, apiVersion = 'v1.1') {
|
|
|
141
146
|
* @returns {Promise<Object>} User data from v2 API
|
|
142
147
|
*/
|
|
143
148
|
export async function getAuthenticatedUser(token, logger) {
|
|
149
|
+
const apiUrl = 'https://api.x.com/2/users/me';
|
|
144
150
|
try {
|
|
145
151
|
const result = await getRequest({
|
|
146
152
|
token,
|
|
147
|
-
uri:
|
|
153
|
+
uri: apiUrl,
|
|
148
154
|
attachUrlPrefix: false,
|
|
149
155
|
convertPayloadToUri: false,
|
|
150
156
|
logger,
|
|
151
157
|
});
|
|
152
158
|
return result.data;
|
|
153
159
|
} catch (e) {
|
|
154
|
-
|
|
160
|
+
loggerInfo(logger, `Failed to call twitter api - getAuthenticatedUser`, {
|
|
161
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
162
|
+
apiUrl,
|
|
163
|
+
status: e?.response?.status,
|
|
164
|
+
responseBody: e?.response?.body,
|
|
165
|
+
error: e?.response?.body?.errors?.[0]?.message ?? e?.message,
|
|
166
|
+
}),
|
|
167
|
+
});
|
|
155
168
|
throw e;
|
|
156
169
|
}
|
|
157
170
|
}
|
|
@@ -208,8 +221,12 @@ export async function getUserInfoFromHandles(token, handles, logger) {
|
|
|
208
221
|
const normalizedData = normalizeUsersData(result.data, result.source);
|
|
209
222
|
return normalizedData || [];
|
|
210
223
|
} catch (e) {
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
loggerInfo(logger, `Failed to call twitter api - getUserInfoFromHandles`, {
|
|
225
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
226
|
+
error: e?.message,
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
throw e;
|
|
213
230
|
}
|
|
214
231
|
}
|
|
215
232
|
|
|
@@ -242,13 +259,13 @@ export async function getUserInfoFromHandle(token, handleId, logger) {
|
|
|
242
259
|
);
|
|
243
260
|
}
|
|
244
261
|
} catch (e) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
loggerInfo(logger, `Failed to call twitter api - getUserInfoFromHandle`, {
|
|
263
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
264
|
+
handleId,
|
|
265
|
+
error: e?.message,
|
|
266
|
+
}),
|
|
267
|
+
});
|
|
268
|
+
throw e;
|
|
252
269
|
}
|
|
253
270
|
}
|
|
254
271
|
|
|
@@ -265,7 +282,12 @@ export async function getDirectMessageImage(token, imageUrl, logger) {
|
|
|
265
282
|
contentType: result.contentType,
|
|
266
283
|
};
|
|
267
284
|
} catch (e) {
|
|
268
|
-
|
|
285
|
+
loggerInfo(logger, `Failed to call twitter api - getDirectMessageImage`, {
|
|
286
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
287
|
+
imageUrl,
|
|
288
|
+
error: e?.message,
|
|
289
|
+
}),
|
|
290
|
+
});
|
|
269
291
|
throw e;
|
|
270
292
|
}
|
|
271
293
|
}
|
|
@@ -288,7 +310,13 @@ export async function getCurrentInfo(token, externalId, logger) {
|
|
|
288
310
|
result.data.retweeted = !!result.data.current_user_retweet;
|
|
289
311
|
return result.data.data[0].public_metrics;
|
|
290
312
|
} catch (error) {
|
|
291
|
-
|
|
313
|
+
loggerInfo(logger, `Failed to call twitter api - getCurrentInfo`, {
|
|
314
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
315
|
+
externalId,
|
|
316
|
+
error: error?.message,
|
|
317
|
+
}),
|
|
318
|
+
});
|
|
319
|
+
throw error;
|
|
292
320
|
}
|
|
293
321
|
}
|
|
294
322
|
|
|
@@ -306,7 +334,13 @@ export async function getMentionHandleInfo(token, externalId, logger) {
|
|
|
306
334
|
});
|
|
307
335
|
return result.data;
|
|
308
336
|
} catch (error) {
|
|
309
|
-
|
|
337
|
+
loggerInfo(logger, `Failed to call twitter api - getMentionHandleInfo`, {
|
|
338
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
339
|
+
externalId,
|
|
340
|
+
error: error?.message,
|
|
341
|
+
}),
|
|
342
|
+
});
|
|
343
|
+
throw error;
|
|
310
344
|
}
|
|
311
345
|
}
|
|
312
346
|
|
|
@@ -332,7 +366,14 @@ export async function retweet(token, sourceId, externalId, logger) {
|
|
|
332
366
|
return false;
|
|
333
367
|
}
|
|
334
368
|
} catch (error) {
|
|
335
|
-
|
|
369
|
+
loggerInfo(logger, `Failed to call twitter api - retweet`, {
|
|
370
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
371
|
+
sourceId,
|
|
372
|
+
externalId,
|
|
373
|
+
error: error?.message,
|
|
374
|
+
}),
|
|
375
|
+
});
|
|
376
|
+
throw error;
|
|
336
377
|
}
|
|
337
378
|
}
|
|
338
379
|
|
|
@@ -355,16 +396,20 @@ export async function unRetweet(token, sourceId, externalId, logger) {
|
|
|
355
396
|
return false;
|
|
356
397
|
}
|
|
357
398
|
} catch (error) {
|
|
358
|
-
|
|
359
|
-
[MeltwaterAttributes.
|
|
399
|
+
loggerInfo(logger, `Failed to call twitter api - unRetweet`, {
|
|
400
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
401
|
+
sourceId,
|
|
402
|
+
externalId,
|
|
403
|
+
error: error?.message,
|
|
404
|
+
}),
|
|
360
405
|
});
|
|
406
|
+
throw error;
|
|
361
407
|
}
|
|
362
408
|
}
|
|
363
409
|
|
|
364
|
-
export async function like(token, externalId, logger) {
|
|
410
|
+
export async function like(token, externalId, logger, authenticatedUser = null) {
|
|
365
411
|
try {
|
|
366
|
-
|
|
367
|
-
const userInfo = await getAuthenticatedUser(token, logger);
|
|
412
|
+
const userInfo = authenticatedUser ?? await getAuthenticatedUser(token, logger);
|
|
368
413
|
const userId = userInfo.data.id;
|
|
369
414
|
|
|
370
415
|
let response = await postRequest({
|
|
@@ -394,15 +439,19 @@ export async function like(token, externalId, logger) {
|
|
|
394
439
|
return false;
|
|
395
440
|
}
|
|
396
441
|
} catch (error) {
|
|
397
|
-
|
|
442
|
+
loggerInfo(logger, `Failed to call twitter api - like`, {
|
|
443
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
444
|
+
externalId,
|
|
445
|
+
error: error?.message,
|
|
446
|
+
}),
|
|
447
|
+
});
|
|
398
448
|
throw error;
|
|
399
449
|
}
|
|
400
450
|
}
|
|
401
451
|
|
|
402
|
-
export async function unLike(token, externalId, logger) {
|
|
452
|
+
export async function unLike(token, externalId, logger, authenticatedUser = null) {
|
|
403
453
|
try {
|
|
404
|
-
|
|
405
|
-
const userInfo = await getAuthenticatedUser(token, logger);
|
|
454
|
+
const userInfo = authenticatedUser ?? await getAuthenticatedUser(token, logger);
|
|
406
455
|
const userId = userInfo.data.id;
|
|
407
456
|
|
|
408
457
|
let response = await deleteRequest({
|
|
@@ -424,15 +473,19 @@ export async function unLike(token, externalId, logger) {
|
|
|
424
473
|
return false;
|
|
425
474
|
}
|
|
426
475
|
} catch (error) {
|
|
427
|
-
|
|
476
|
+
loggerInfo(logger, `Failed to call twitter api - unLike`, {
|
|
477
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
478
|
+
externalId,
|
|
479
|
+
error: error?.message,
|
|
480
|
+
}),
|
|
481
|
+
});
|
|
428
482
|
throw error;
|
|
429
483
|
}
|
|
430
484
|
}
|
|
431
485
|
|
|
432
|
-
export async function followUser(token, profileId, logger) {
|
|
486
|
+
export async function followUser(token, profileId, logger, authenticatedUser = null) {
|
|
433
487
|
try {
|
|
434
|
-
|
|
435
|
-
const userInfo = await getAuthenticatedUser(token, logger);
|
|
488
|
+
const userInfo = authenticatedUser ?? await getAuthenticatedUser(token, logger);
|
|
436
489
|
const userId = userInfo.data.id;
|
|
437
490
|
|
|
438
491
|
let response = await postRequest({
|
|
@@ -452,14 +505,19 @@ export async function followUser(token, profileId, logger) {
|
|
|
452
505
|
return false;
|
|
453
506
|
}
|
|
454
507
|
} catch (error) {
|
|
455
|
-
|
|
508
|
+
loggerInfo(logger, `Failed to call twitter api - followUser`, {
|
|
509
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
510
|
+
profileId,
|
|
511
|
+
error: error?.message,
|
|
512
|
+
}),
|
|
513
|
+
});
|
|
514
|
+
throw error;
|
|
456
515
|
}
|
|
457
516
|
}
|
|
458
517
|
|
|
459
|
-
export async function unFollowUser(token, profileId, logger) {
|
|
518
|
+
export async function unFollowUser(token, profileId, logger, authenticatedUser = null) {
|
|
460
519
|
try {
|
|
461
|
-
|
|
462
|
-
const userInfo = await getAuthenticatedUser(token, logger);
|
|
520
|
+
const userInfo = authenticatedUser ?? await getAuthenticatedUser(token, logger);
|
|
463
521
|
const userId = userInfo.data.id;
|
|
464
522
|
|
|
465
523
|
let response = await deleteRequest({
|
|
@@ -478,14 +536,19 @@ export async function unFollowUser(token, profileId, logger) {
|
|
|
478
536
|
return false;
|
|
479
537
|
}
|
|
480
538
|
} catch (error) {
|
|
481
|
-
|
|
539
|
+
loggerInfo(logger, `Failed to call twitter api - unFollowUser`, {
|
|
540
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
541
|
+
profileId,
|
|
542
|
+
error: error?.message,
|
|
543
|
+
}),
|
|
544
|
+
});
|
|
545
|
+
throw error;
|
|
482
546
|
}
|
|
483
547
|
}
|
|
484
548
|
|
|
485
|
-
export async function userFollowStatus(token, profileId, logger) {
|
|
549
|
+
export async function userFollowStatus(token, profileId, logger, authenticatedUser = null) {
|
|
486
550
|
try {
|
|
487
|
-
|
|
488
|
-
const userInfo = await getAuthenticatedUser(token, logger);
|
|
551
|
+
const userInfo = authenticatedUser ?? await getAuthenticatedUser(token, logger);
|
|
489
552
|
const userId = userInfo.data.id;
|
|
490
553
|
|
|
491
554
|
// Check if authenticated user is following the target user
|
|
@@ -528,7 +591,7 @@ export async function userFollowStatus(token, profileId, logger) {
|
|
|
528
591
|
// if we hit a minor rate limit here, we wait for 5 seconds before attempting again, usually long enough to continue
|
|
529
592
|
await new Promise((r) => setTimeout(r, 5000));
|
|
530
593
|
|
|
531
|
-
return userFollowStatus(token, profileId, logger);
|
|
594
|
+
return userFollowStatus(token, profileId, logger, authenticatedUser);
|
|
532
595
|
}
|
|
533
596
|
}
|
|
534
597
|
}
|
|
@@ -601,11 +664,14 @@ export async function getBrandUserRelationship(
|
|
|
601
664
|
},
|
|
602
665
|
};
|
|
603
666
|
} catch (error) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
667
|
+
loggerInfo(logger, `Failed to call twitter api - getBrandUserRelationship`, {
|
|
668
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
669
|
+
profileId,
|
|
670
|
+
brandProfileId,
|
|
671
|
+
error: error?.message,
|
|
672
|
+
}),
|
|
673
|
+
});
|
|
674
|
+
throw error;
|
|
609
675
|
}
|
|
610
676
|
}
|
|
611
677
|
|
|
@@ -888,7 +954,6 @@ async function publishTweet(token, payload, query, isDirectMessage, logger) {
|
|
|
888
954
|
|
|
889
955
|
return normalizedResponse;
|
|
890
956
|
} catch (err) {
|
|
891
|
-
loggerError(logger, `Twitter publish exception details`, err);
|
|
892
957
|
throw err;
|
|
893
958
|
}
|
|
894
959
|
}
|
|
@@ -936,7 +1001,6 @@ async function publishDirectMessage(token, payload, query, logger) {
|
|
|
936
1001
|
|
|
937
1002
|
return normalizedResponse;
|
|
938
1003
|
} catch (err) {
|
|
939
|
-
loggerError(logger, `Twitter DM send failed`, err);
|
|
940
1004
|
throw err;
|
|
941
1005
|
}
|
|
942
1006
|
}
|
|
@@ -1081,10 +1145,14 @@ async function doRequest({
|
|
|
1081
1145
|
);
|
|
1082
1146
|
return reject(e);
|
|
1083
1147
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1148
|
+
loggerInfo(logger, `Failed to call twitter api - doRequest`, {
|
|
1149
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
1150
|
+
url,
|
|
1151
|
+
convertPayloadToUri,
|
|
1152
|
+
payload: JSON.stringify(payload),
|
|
1153
|
+
status: e?.response?.status,
|
|
1154
|
+
error: e?.response?.body?.errors?.[0]?.message ?? e?.message,
|
|
1155
|
+
}),
|
|
1088
1156
|
});
|
|
1089
1157
|
reject(e);
|
|
1090
1158
|
}
|
|
@@ -1173,7 +1241,6 @@ async function uploadMedia(attachment, token, discussionType, logger) {
|
|
|
1173
1241
|
return mediaIdString;
|
|
1174
1242
|
}
|
|
1175
1243
|
} catch (e) {
|
|
1176
|
-
loggerError(logger, `Failed uploading media`, e);
|
|
1177
1244
|
if (filePath) {
|
|
1178
1245
|
removeMedia(filePath, logger);
|
|
1179
1246
|
}
|
|
@@ -1217,7 +1284,13 @@ async function simpleMediaUpload(fileData, mimeType, mediaCategory, token, logge
|
|
|
1217
1284
|
|
|
1218
1285
|
return result.body.media_id_string;
|
|
1219
1286
|
} catch (e) {
|
|
1220
|
-
|
|
1287
|
+
loggerInfo(logger, `Failed to call twitter api - simpleMediaUpload`, {
|
|
1288
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
1289
|
+
mimeType,
|
|
1290
|
+
mediaCategory,
|
|
1291
|
+
error: e?.message,
|
|
1292
|
+
}),
|
|
1293
|
+
});
|
|
1221
1294
|
throw e;
|
|
1222
1295
|
}
|
|
1223
1296
|
}
|
|
@@ -1299,7 +1372,6 @@ async function chunkedMediaUpload(
|
|
|
1299
1372
|
|
|
1300
1373
|
return mediaId;
|
|
1301
1374
|
} catch (e) {
|
|
1302
|
-
loggerError(logger, 'Error in chunked media upload', e);
|
|
1303
1375
|
throw e;
|
|
1304
1376
|
}
|
|
1305
1377
|
}
|
|
@@ -1359,11 +1431,12 @@ async function mediaUploadRequest(params, token, logger) {
|
|
|
1359
1431
|
const result = await request;
|
|
1360
1432
|
return result.body;
|
|
1361
1433
|
} catch (e) {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1434
|
+
loggerInfo(logger, `Failed to call twitter api - mediaUploadRequest`, {
|
|
1435
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
1436
|
+
command: params.command,
|
|
1437
|
+
error: e?.message,
|
|
1438
|
+
}),
|
|
1439
|
+
});
|
|
1367
1440
|
throw e;
|
|
1368
1441
|
}
|
|
1369
1442
|
}
|
|
@@ -1421,13 +1494,20 @@ function removeMedia(file, logger) {
|
|
|
1421
1494
|
try {
|
|
1422
1495
|
fs.unlink(file, function (err) {
|
|
1423
1496
|
if (err) {
|
|
1424
|
-
|
|
1497
|
+
loggerInfo(logger, `Failed to call twitter api - removeMedia`, {
|
|
1498
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
1499
|
+
file,
|
|
1500
|
+
error: err?.message,
|
|
1501
|
+
}),
|
|
1502
|
+
});
|
|
1425
1503
|
}
|
|
1426
1504
|
});
|
|
1427
1505
|
} catch (e) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1506
|
+
loggerInfo(logger, `Failed to call twitter api - removeMedia`, {
|
|
1507
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
1508
|
+
file,
|
|
1509
|
+
error: e?.message,
|
|
1510
|
+
}),
|
|
1511
|
+
});
|
|
1432
1512
|
}
|
|
1433
1513
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import superagent from 'superagent';
|
|
2
2
|
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
-
import {
|
|
3
|
+
import { loggerInfo, MeltwaterAttributes } from '../../lib/logger.helpers.js';
|
|
4
4
|
|
|
5
5
|
const YOUTUBE_API_URL = "https://www.googleapis.com/youtube/v3/"
|
|
6
6
|
|
|
@@ -20,22 +20,12 @@ async function sendPost(
|
|
|
20
20
|
.set('Authorization', `Bearer ${token}`)
|
|
21
21
|
.send(postData);
|
|
22
22
|
} catch (err) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
loggerError(logger,
|
|
30
|
-
`Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
31
|
-
);
|
|
32
|
-
} else {
|
|
33
|
-
loggerError(logger,
|
|
34
|
-
`Failed to call youtube api for paramString ${paramString}`,
|
|
35
|
-
err
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
23
|
+
loggerInfo(logger, 'Failed to call youtube api - sendPost', {
|
|
24
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
25
|
+
paramString,
|
|
26
|
+
error: err?.response?.body?.error?.message ?? err?.message,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
39
29
|
throw err;
|
|
40
30
|
}
|
|
41
31
|
|
|
@@ -56,33 +46,24 @@ export async function sendRequest(
|
|
|
56
46
|
.set('Authorization', `Bearer ${token}`)
|
|
57
47
|
.send();
|
|
58
48
|
} catch (err) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
loggerError( logger,
|
|
66
|
-
`Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
67
|
-
);
|
|
68
|
-
} else {
|
|
69
|
-
loggerError( logger,
|
|
70
|
-
`Failed to call youtube api for paramString ${paramString}`,
|
|
71
|
-
err
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
49
|
+
loggerInfo(logger, 'Failed to call youtube api - sendRequest', {
|
|
50
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
51
|
+
paramString,
|
|
52
|
+
error: err?.response?.body?.error?.message ?? err?.message,
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
75
55
|
throw err;
|
|
76
56
|
}
|
|
77
57
|
|
|
78
58
|
if (response.status !== 200) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
59
|
+
loggerInfo(logger, 'Failed to call youtube api - sendRequest', {
|
|
60
|
+
[MeltwaterAttributes.PAYLOADDATA]: JSON.stringify({
|
|
61
|
+
paramString,
|
|
62
|
+
status: response.status,
|
|
63
|
+
body: response.body,
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
let error = new Error(`Failed to call youtube api`);
|
|
86
67
|
error.code = response.status;
|
|
87
68
|
throw error;
|
|
88
69
|
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _logger = _interopRequireDefault(require("../lib/logger.js"));
|
|
8
|
-
var _irClien = require("../data-access/http/ir.clien.jst");
|
|
9
|
-
var _xrunes = _interopRequireDefault(require("@meltwater/xrunes"));
|
|
10
|
-
var _xrunesCore = _interopRequireDefault(require("@meltwater/xrunes-core"));
|
|
11
|
-
var _loggerHelpers = require("../lib/logger.helpers.js");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
class HiddenCommentHelper {
|
|
14
|
-
constructor(_ref) {
|
|
15
|
-
let {
|
|
16
|
-
company,
|
|
17
|
-
user,
|
|
18
|
-
traceId
|
|
19
|
-
} = _ref;
|
|
20
|
-
this.irClient = new _irClien.IRClient({
|
|
21
|
-
company,
|
|
22
|
-
user,
|
|
23
|
-
traceId
|
|
24
|
-
});
|
|
25
|
-
this.xRunes = new _xrunes.default();
|
|
26
|
-
this.xRunes.registerLibrary(_xrunesCore.default);
|
|
27
|
-
}
|
|
28
|
-
shouldHandle(message) {
|
|
29
|
-
return message.metaData.discussionType === 'qt';
|
|
30
|
-
}
|
|
31
|
-
async hideChildren(message, markHidden) {
|
|
32
|
-
let {
|
|
33
|
-
body: {
|
|
34
|
-
publishDate: {
|
|
35
|
-
date: publishDate
|
|
36
|
-
} = {}
|
|
37
|
-
} = {},
|
|
38
|
-
metaData: {
|
|
39
|
-
externalId,
|
|
40
|
-
source: {
|
|
41
|
-
socialOriginType
|
|
42
|
-
} = {}
|
|
43
|
-
} = {},
|
|
44
|
-
systemData: {
|
|
45
|
-
connectionsCredential: credentialId,
|
|
46
|
-
policies: {
|
|
47
|
-
storage: {
|
|
48
|
-
privateTo: companyId
|
|
49
|
-
} = {}
|
|
50
|
-
} = {}
|
|
51
|
-
} = {}
|
|
52
|
-
} = message;
|
|
53
|
-
let operation;
|
|
54
|
-
let query = {
|
|
55
|
-
type: 'x:match',
|
|
56
|
-
matchQuery: {
|
|
57
|
-
type: 'all',
|
|
58
|
-
allQueries: [{
|
|
59
|
-
type: 'x:dateRange',
|
|
60
|
-
field: 'body.publishDate.date',
|
|
61
|
-
from: publishDate
|
|
62
|
-
}, {
|
|
63
|
-
type: 'term',
|
|
64
|
-
field: 'metaData.inReplyTo.externalId',
|
|
65
|
-
value: externalId
|
|
66
|
-
}]
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
if (markHidden) {
|
|
70
|
-
operation = 'addToSet';
|
|
71
|
-
query.notMatchQuery = {
|
|
72
|
-
type: 'term',
|
|
73
|
-
field: 'metaData.applicationTags',
|
|
74
|
-
value: 'parentHidden'
|
|
75
|
-
};
|
|
76
|
-
} else {
|
|
77
|
-
operation = 'removeFromSet';
|
|
78
|
-
query.matchQuery.allQueries.push({
|
|
79
|
-
type: 'term',
|
|
80
|
-
field: 'metaData.applicationTags',
|
|
81
|
-
value: 'parentHidden'
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
let runes = {
|
|
85
|
-
query,
|
|
86
|
-
transformers: [{
|
|
87
|
-
type: 'idml',
|
|
88
|
-
script: `action = "update" target = "revision" revisionGroup = "${companyId}" documentId = id operations = [{"operation": "${operation}", "value": ["parentHidden"], "fieldPath": "metaData.applicationTags"}]`
|
|
89
|
-
}],
|
|
90
|
-
overlayGroups: [companyId],
|
|
91
|
-
fields: ['id'],
|
|
92
|
-
outputConfiguration: {
|
|
93
|
-
type: 's3',
|
|
94
|
-
region: 'eu-west-1',
|
|
95
|
-
roleArn: process.env.EXPORT_API_ROLE_ARN,
|
|
96
|
-
externalId: process.env.EXPORT_API_EXTERNAL_ID,
|
|
97
|
-
s3BucketName: process.env.EXPORT_API_S3_BUCKET,
|
|
98
|
-
s3KeyPrefix: process.env.EXPORT_API_S3_PREFIX,
|
|
99
|
-
// the property is optional, the trailing / isn't
|
|
100
|
-
batchSize: 1000 // the property is optional, must be >= 100 and <= 20000. Default is 20000
|
|
101
|
-
},
|
|
102
|
-
metaData: {
|
|
103
|
-
companyId
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
runes.query = await this.xRunes.render(runes.query);
|
|
107
|
-
_logger.default.debug(`export api query: ${JSON.stringify(runes.query)}`, {
|
|
108
|
-
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
|
|
109
|
-
[_loggerHelpers.MeltwaterAttributes.CREDENTIALID]: credentialId
|
|
110
|
-
});
|
|
111
|
-
let results = await this.irClient.export(runes);
|
|
112
|
-
_logger.default.debug(`export api result: ${JSON.stringify(results)}`, {
|
|
113
|
-
[_loggerHelpers.MeltwaterAttributes.COMPANYID]: companyId,
|
|
114
|
-
[_loggerHelpers.MeltwaterAttributes.CREDENTIALID]: credentialId
|
|
115
|
-
});
|
|
116
|
-
return results;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
var _default = exports.default = HiddenCommentHelper;
|