@meltwater/conversations-api-services 1.0.19 → 1.0.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.
Files changed (70) hide show
  1. package/.github/workflows/release.yml +2 -0
  2. package/babel.config.js +18 -0
  3. package/dist/cjs/data-access/http/InstagramVideoClient.js +42 -0
  4. package/dist/cjs/data-access/http/WarpZoneApi.client.js +32 -0
  5. package/dist/cjs/data-access/http/amazonS3.js +44 -0
  6. package/dist/cjs/data-access/http/asset-manager-tvm.client.js +35 -0
  7. package/dist/cjs/data-access/http/companiesApi.client.js +38 -0
  8. package/dist/cjs/data-access/http/credentialsApi.client.js +102 -0
  9. package/dist/cjs/data-access/http/entitlementsApi.client.js +40 -0
  10. package/dist/cjs/data-access/http/facebook.native.js +344 -0
  11. package/dist/cjs/data-access/http/facebookApi.client.js +631 -0
  12. package/dist/cjs/data-access/http/featureToggleApi.client.js +31 -0
  13. package/dist/cjs/data-access/http/identityServices.client.js +97 -0
  14. package/dist/cjs/data-access/http/instagramApi.client.js +428 -0
  15. package/dist/cjs/data-access/http/ir.client.js +242 -0
  16. package/dist/cjs/data-access/http/linkedInApi.client.js +491 -0
  17. package/dist/cjs/data-access/http/masf.client.js +101 -0
  18. package/dist/cjs/data-access/http/tiktok.native.js +162 -0
  19. package/dist/cjs/data-access/http/tiktokApi.client.js +441 -0
  20. package/dist/cjs/data-access/index.js +132 -0
  21. package/dist/cjs/errors/engage-error.js +16 -0
  22. package/dist/cjs/errors/http-error.js +23 -0
  23. package/dist/cjs/lib/applicationTags.helpers.js +30 -0
  24. package/dist/cjs/lib/configuration.js +14 -0
  25. package/dist/cjs/lib/document-action-events.js +12 -0
  26. package/dist/cjs/lib/externalId.helpers.js +19 -0
  27. package/dist/cjs/lib/hidden.helpers.js +13 -0
  28. package/dist/cjs/lib/hiddenComment.helper.js +119 -0
  29. package/dist/cjs/lib/logger.helpers.js +68 -0
  30. package/dist/cjs/lib/logger.js +23 -0
  31. package/dist/cjs/lib/message.helpers.js +58 -0
  32. package/dist/cjs/lib/metrics.helper.js +97 -0
  33. package/dist/esm/data-access/http/InstagramVideoClient.js +34 -0
  34. package/dist/esm/data-access/http/WarpZoneApi.client.js +24 -0
  35. package/dist/esm/data-access/http/amazonS3.js +37 -0
  36. package/dist/esm/data-access/http/asset-manager-tvm.client.js +28 -0
  37. package/dist/esm/data-access/http/companiesApi.client.js +30 -0
  38. package/dist/esm/data-access/http/credentialsApi.client.js +92 -0
  39. package/dist/esm/data-access/http/entitlementsApi.client.js +32 -0
  40. package/dist/esm/data-access/http/facebook.native.js +325 -0
  41. package/dist/esm/data-access/http/facebookApi.client.js +621 -0
  42. package/dist/esm/data-access/http/featureToggleApi.client.js +23 -0
  43. package/dist/esm/data-access/http/identityServices.client.js +89 -0
  44. package/dist/esm/data-access/http/instagramApi.client.js +420 -0
  45. package/dist/esm/data-access/http/ir.client.js +234 -0
  46. package/dist/esm/data-access/http/linkedInApi.client.js +481 -0
  47. package/dist/esm/data-access/http/masf.client.js +93 -0
  48. package/dist/esm/data-access/http/tiktok.native.js +146 -0
  49. package/dist/esm/data-access/http/tiktokApi.client.js +433 -0
  50. package/dist/esm/data-access/index.js +30 -0
  51. package/dist/esm/errors/engage-error.js +9 -0
  52. package/dist/esm/errors/http-error.js +16 -0
  53. package/dist/esm/lib/applicationTags.helpers.js +22 -0
  54. package/dist/esm/lib/configuration.js +8 -0
  55. package/dist/esm/lib/document-action-events.js +6 -0
  56. package/dist/esm/lib/externalId.helpers.js +12 -0
  57. package/dist/esm/lib/hidden.helpers.js +6 -0
  58. package/dist/esm/lib/hiddenComment.helper.js +112 -0
  59. package/dist/esm/lib/logger.helpers.js +60 -0
  60. package/dist/esm/lib/logger.js +16 -0
  61. package/dist/esm/lib/message.helpers.js +52 -0
  62. package/dist/esm/lib/metrics.helper.js +90 -0
  63. package/package.json +14 -4
  64. package/src/data-access/http/facebook.native.js +542 -0
  65. package/src/data-access/http/tiktok.native.js +248 -0
  66. package/src/data-access/index.js +4 -0
  67. package/src/errors/engage-error.js +11 -0
  68. package/src/errors/http-error.js +19 -0
  69. package/src/lib/logger.helpers.js +15 -0
  70. package/src/lib/message.helpers.js +7 -1
@@ -0,0 +1,6 @@
1
+ export function socialTypesThatCanBeHidden() {
2
+ return ['instagram', 'facebook', 'tiktok'];
3
+ }
4
+ export function isThisHiddenEligible(document) {
5
+ return socialTypesThatCanBeHidden().includes(document.metaData.source.socialOriginType);
6
+ }
@@ -0,0 +1,112 @@
1
+ import logger from '../lib/logger.js';
2
+ import { IRClient } from '../data-access/http/ir.clien.jst';
3
+ import XRunes from '@meltwater/xrunes';
4
+ import xRunesCore from '@meltwater/xrunes-core';
5
+ import { MeltwaterAttributes } from '../lib/logger.helpers.js';
6
+ class HiddenCommentHelper {
7
+ constructor(_ref) {
8
+ let {
9
+ company,
10
+ user,
11
+ traceId
12
+ } = _ref;
13
+ this.irClient = new IRClient({
14
+ company,
15
+ user,
16
+ traceId
17
+ });
18
+ this.xRunes = new XRunes();
19
+ this.xRunes.registerLibrary(xRunesCore);
20
+ }
21
+ shouldHandle(message) {
22
+ return message.metaData.discussionType === 'qt';
23
+ }
24
+ async hideChildren(message, markHidden) {
25
+ let {
26
+ body: {
27
+ publishDate: {
28
+ date: publishDate
29
+ } = {}
30
+ } = {},
31
+ metaData: {
32
+ externalId,
33
+ source: {
34
+ socialOriginType
35
+ } = {}
36
+ } = {},
37
+ systemData: {
38
+ connectionsCredential: credentialId,
39
+ policies: {
40
+ storage: {
41
+ privateTo: companyId
42
+ } = {}
43
+ } = {}
44
+ } = {}
45
+ } = message;
46
+ let operation;
47
+ let query = {
48
+ type: 'x:match',
49
+ matchQuery: {
50
+ type: 'all',
51
+ allQueries: [{
52
+ type: 'x:dateRange',
53
+ field: 'body.publishDate.date',
54
+ from: publishDate
55
+ }, {
56
+ type: 'term',
57
+ field: 'metaData.inReplyTo.externalId',
58
+ value: externalId
59
+ }]
60
+ }
61
+ };
62
+ if (markHidden) {
63
+ operation = 'addToSet';
64
+ query.notMatchQuery = {
65
+ type: 'term',
66
+ field: 'metaData.applicationTags',
67
+ value: 'parentHidden'
68
+ };
69
+ } else {
70
+ operation = 'removeFromSet';
71
+ query.matchQuery.allQueries.push({
72
+ type: 'term',
73
+ field: 'metaData.applicationTags',
74
+ value: 'parentHidden'
75
+ });
76
+ }
77
+ let runes = {
78
+ query,
79
+ transformers: [{
80
+ type: 'idml',
81
+ script: `action = "update" target = "revision" revisionGroup = "${companyId}" documentId = id operations = [{"operation": "${operation}", "value": ["parentHidden"], "fieldPath": "metaData.applicationTags"}]`
82
+ }],
83
+ overlayGroups: [companyId],
84
+ fields: ['id'],
85
+ outputConfiguration: {
86
+ type: 's3',
87
+ region: 'eu-west-1',
88
+ roleArn: process.env.EXPORT_API_ROLE_ARN,
89
+ externalId: process.env.EXPORT_API_EXTERNAL_ID,
90
+ s3BucketName: process.env.EXPORT_API_S3_BUCKET,
91
+ s3KeyPrefix: process.env.EXPORT_API_S3_PREFIX,
92
+ // the property is optional, the trailing / isn't
93
+ batchSize: 1000 // the property is optional, must be >= 100 and <= 20000. Default is 20000
94
+ },
95
+ metaData: {
96
+ companyId
97
+ }
98
+ };
99
+ runes.query = await this.xRunes.render(runes.query);
100
+ logger.debug(`export api query: ${JSON.stringify(runes.query)}`, {
101
+ [MeltwaterAttributes.COMPANYID]: companyId,
102
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
103
+ });
104
+ let results = await this.irClient.export(runes);
105
+ logger.debug(`export api result: ${JSON.stringify(results)}`, {
106
+ [MeltwaterAttributes.COMPANYID]: companyId,
107
+ [MeltwaterAttributes.CREDENTIALID]: credentialId
108
+ });
109
+ return results;
110
+ }
111
+ }
112
+ export default HiddenCommentHelper;
@@ -0,0 +1,60 @@
1
+ const MeltwaterAttributes = {
2
+ COMPANYID: 'meltwater.company.id',
3
+ // Unique identifier of a company as it applies to meltwater search
4
+ DOCUMENTID: 'meltwater.document.id',
5
+ // Unique identifier of a document indexed into search
6
+ DOCUMENTLANG: 'meltwater.document.lang',
7
+ // Two-letter country code (lower-case) of the original document
8
+ DOCUMENTEXTERNALID: 'meltwater.document.external_id',
9
+ // The external ID of the document
10
+ REQUESTFORMAT: 'meltwater.document.request_format',
11
+ // The document format requested (“gyda”/”quiddity”)
12
+ DOCUMENTIDS: 'meltwater.document_ids',
13
+ // A list of document Ids
14
+ SEARCHIDS: 'meltwater.search_ids',
15
+ // List of IDs of saved searches.
16
+ AUTHORLISTIDS: 'meltwater.authorlist_ids',
17
+ // List of IDs of author lists.
18
+ TAGNAMES: 'meltwater.tag_names',
19
+ // List of tag names
20
+ SEARCHID: 'meltwater.search.id',
21
+ // ID for a saved search
22
+ CREDENTIALID: 'meltwater.social.credential_id',
23
+ // Identifier for Owned and Paid Social Connections.
24
+ CREDENTIALIDS: 'meltwater.social.credential_ids',
25
+ // List of Credential IDs
26
+ SOCIALEXTERNALID: 'meltwater.social.external_id',
27
+ // External ID for Owned and Paid Social Connections.
28
+ ASSETID: 'meltwater.asset.id',
29
+ // Asset ID in the asset library
30
+ ASSETIDS: 'meltwater.asset.ids',
31
+ // List of Asset IDs
32
+ WORKSPACEID: 'meltwater.workspace.id',
33
+ // Workspace ID
34
+ PRODUCTTYPE: 'meltwater.product_type',
35
+ // The name of the product for the search request
36
+ CLIENTNAME: 'meltwater.client_name',
37
+ // The “client_name” identifier used for API calls
38
+ ORIGINALCLIENTNAME: 'meltwater.original_client_name',
39
+ // The originating “client_name” identifier used for API calls
40
+ AUTHKEYID: 'meltwater.auth.kid',
41
+ // The JWT Key ID for the request.
42
+ AUTHEXP: 'meltwater.auth.exp',
43
+ // The expiration of the auth credentials.
44
+ AUTHPERMISSIONS: 'meltwater.auth.permissions',
45
+ // List of auth permermissions.
46
+ USERID: 'user.id' // ID of the user
47
+ };
48
+ export function loggerDebug(logger, message) {
49
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
50
+ if (logger) logger.debug(message, meta);
51
+ }
52
+ export function loggerInfo(logger, message) {
53
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
54
+ if (logger) logger.info(message, meta);
55
+ }
56
+ export function loggerError(logger, message) {
57
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
58
+ if (logger) logger.error(message, meta);
59
+ }
60
+ export { MeltwaterAttributes };
@@ -0,0 +1,16 @@
1
+ import winston from 'winston';
2
+ import { ecsFormat } from '@elastic/ecs-winston-format';
3
+ const format = ecsFormat({
4
+ serviceName: process.env.NODE_ENV ? `conversations-api-services-${process.env.NODE_ENV}` : 'conversations-api-services',
5
+ serviceVersion: process.env.npm_package_version,
6
+ serviceEnvironment: process.env.NODE_ENV
7
+ });
8
+ const logger = winston.createLogger({
9
+ level: process.env.LOG_LEVEL || 'info',
10
+ format,
11
+ defaultMeta: {},
12
+ transports: [new winston.transports.Console({
13
+ format
14
+ })]
15
+ });
16
+ export default logger;
@@ -0,0 +1,52 @@
1
+ export function isMention(_ref, credential) {
2
+ let {
3
+ appData: {
4
+ isMention = false
5
+ } = {},
6
+ body: {
7
+ mentions = []
8
+ } = {},
9
+ metaData: {
10
+ authors: [{
11
+ authorInfo: {
12
+ externalId: authorExternalId,
13
+ handle: authorHandle
14
+ } = {}
15
+ } = {}] = [{}],
16
+ inReplyTo: {
17
+ author: {
18
+ externalId: inReplyToExternalId,
19
+ handle: inReplyToHandle
20
+ } = {}
21
+ } = {},
22
+ discussionType = '',
23
+ source: {
24
+ socialOriginType
25
+ } = {}
26
+ } = {},
27
+ providerSpecific
28
+ } = _ref;
29
+ if (socialOriginType == 'twitter' && discussionType != 'og') {
30
+ return false;
31
+ }
32
+ // if inReplyToExternalId is the same as the credential's social_account_id, then it's not a mention
33
+ if (inReplyToExternalId && credential.social_account_id && inReplyToExternalId === credential.social_account_id || inReplyToHandle === credential.username) {
34
+ return false;
35
+ }
36
+ if (authorExternalId && credential.social_account_id && authorExternalId === credential.social_account_id || authorHandle?.length && (authorHandle.toLowerCase() === credential.username?.toLowerCase || authorHandle.toLowerCase() === credential.handle?.toLowerCase())) {
37
+ return false;
38
+ }
39
+ let retIsMention = (['og', 're', 'qt'].includes(discussionType) || discussionType === 'dm' && socialOriginType === 'instagram') && (mentions?.length && mentions.some(mention => mention.toLowerCase() === credential.pageName?.toLowerCase() || mention.toLowerCase() === credential.target_page_name?.toLowerCase() || mention.toLowerCase() === credential.userName?.toLowerCase() || mention.toLowerCase() === credential.username?.toLowerCase()) || isMention && socialOriginType === 'facebook');
40
+ if (providerSpecific) {
41
+ let hasMention = providerSpecific.some(_ref2 => {
42
+ let {
43
+ facebookPostType
44
+ } = _ref2;
45
+ return facebookPostType === 'mention';
46
+ });
47
+ if (hasMention) {
48
+ retIsMention = true;
49
+ }
50
+ }
51
+ return retIsMention;
52
+ }
@@ -0,0 +1,90 @@
1
+ import Prometheus from 'prom-client';
2
+ import logger from './logger.js';
3
+ const podMetricsByName = new Map();
4
+ const metricNames = ['irGetByDocumentId', 'irRatelimited', 'irSearch'];
5
+
6
+ // todo: make this a dynamic process
7
+ const irGetByDocumentIdHistogram = new Prometheus.Histogram({
8
+ name: 'irGetByDocumentId_Avg_Reponse_Time',
9
+ help: 'metric_help',
10
+ buckets: Prometheus.linearBuckets(0, 200, 40)
11
+ });
12
+ const irGetByDocumentIdCountHistogram = new Prometheus.Histogram({
13
+ name: 'irGetByDocumentId_Count',
14
+ help: 'metric_help',
15
+ buckets: Prometheus.linearBuckets(0, 1, 40)
16
+ });
17
+ metricNames.forEach(metricName => {
18
+ podMetricsByName.set(metricName, new Prometheus.Counter({
19
+ name: metricName,
20
+ help: `${metricName}_help`
21
+ }));
22
+ });
23
+ class Metrics {
24
+ constructor() {
25
+ this.requestMetricsByName = new Map();
26
+ metricNames.forEach(metricName => {
27
+ this.requestMetricsByName.set(metricName, []);
28
+ });
29
+ this.getMetrics = metricName => {
30
+ return {
31
+ podMetrics: podMetricsByName.get(metricName),
32
+ requestMetrics: this.requestMetricsByName.get(metricName)
33
+ };
34
+ };
35
+ }
36
+ count(metricName) {
37
+ const {
38
+ podMetrics,
39
+ requestMetrics
40
+ } = this.getMetrics(metricName);
41
+ if (podMetrics) {
42
+ podMetrics.inc();
43
+ } else {
44
+ logger.error(`No pod level metric exists for ${metricName}`);
45
+ }
46
+ const metricObject = {
47
+ type: 'count',
48
+ timestamp: Date.now()
49
+ };
50
+ if (requestMetrics) {
51
+ requestMetrics.push(metricObject);
52
+ }
53
+ return metricObject;
54
+ }
55
+ finishOperation(metricName, metricObject) {
56
+ const {
57
+ requestMetrics
58
+ } = this.getMetrics(metricName);
59
+ if (requestMetrics) {
60
+ const matchingMetric = requestMetrics.find(requestMetricExiting => requestMetricExiting.timestamp === metricObject.timestamp);
61
+ matchingMetric.duration = Date.now() - matchingMetric.timestamp;
62
+ }
63
+ }
64
+ async somethingCompleted() {
65
+ let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'IR.getByDocumentId';
66
+ let start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
67
+ } // duration math
68
+ async finishRequest() {
69
+ const {
70
+ requestMetrics
71
+ } = this.getMetrics('irGetByDocumentId');
72
+ let arrHasDuration = requestMetrics.filter(metric => metric.duration);
73
+ if (arrHasDuration.length) {
74
+ let avgDuration = arrHasDuration.reduce((avg, metric) => avg + metric.duration, 0) / arrHasDuration.length;
75
+ irGetByDocumentIdHistogram.observe(avgDuration);
76
+ }
77
+ if (requestMetrics.length > 0) {
78
+ irGetByDocumentIdCountHistogram.observe(requestMetrics.length);
79
+ }
80
+ }
81
+ }
82
+ function createEnum(values) {
83
+ const enumObject = {};
84
+ for (const val of values) {
85
+ enumObject[val] = val;
86
+ }
87
+ return Object.freeze(enumObject);
88
+ }
89
+ const metricN = createEnum(metricNames);
90
+ export { Metrics, metricN };
package/package.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "name": "@meltwater/conversations-api-services",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Repository to contain all conversations api services shared across our services",
5
- "type": "module",
6
- "main": "src/data-access/index.js",
5
+ "main": "dist/cjs/data-access/index.js",
6
+ "module": "dist/esm/data-access/index.js",
7
+ "exports": {
8
+ "require": "./dist/cjs/data-access/index.js",
9
+ "import": "./dist/esm/data-access/index.js"
10
+ },
7
11
  "directories": {
8
12
  "doc": "docs"
9
13
  },
10
14
  "prettier": "@meltwater/engage-prettier-config",
11
15
  "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1"
16
+ "test": "echo \"Error: no test specified\" && exit 1",
17
+ "build:cjs": "BABEL_ENV=cjs babel src --out-dir dist/cjs",
18
+ "build:esm": "BABEL_ENV=esm babel src --out-dir dist/esm",
19
+ "build": "npm run build:cjs && npm run build:esm"
13
20
  },
14
21
  "repository": {
15
22
  "type": "git",
@@ -41,6 +48,9 @@
41
48
  "winston": "^3.11.0"
42
49
  },
43
50
  "devDependencies": {
51
+ "@babel/cli": "^7.25.9",
52
+ "@babel/core": "^7.26.0",
53
+ "@babel/preset-env": "^7.26.0",
44
54
  "@meltwater/engage-prettier-config": "^1.0.0"
45
55
  }
46
56
  }