@meltwater/conversations-api-services 1.1.7 → 1.1.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.
- package/.github/workflows/codeql-analysis.yml +24 -0
- package/dist/cjs/data-access/http/threads.native.js +21 -0
- package/dist/cjs/data-access/http/twitter.native.js +8 -0
- package/dist/cjs/lib/logger.helpers.js +9 -0
- package/dist/esm/data-access/http/threads.native.js +20 -0
- package/dist/esm/data-access/http/twitter.native.js +8 -0
- package/dist/esm/lib/logger.helpers.js +8 -0
- package/package.json +1 -1
- package/src/data-access/http/threads.native.js +22 -0
- package/src/data-access/http/twitter.native.js +8 -0
- package/src/lib/logger.helpers.js +8 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: "Code Scanning"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
actions: write
|
|
14
|
+
contents: read
|
|
15
|
+
security-events: write
|
|
16
|
+
packages: read
|
|
17
|
+
pull-requests: read
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
code-scan-analysis:
|
|
22
|
+
name: Code Scan Analysis
|
|
23
|
+
secrets: inherit
|
|
24
|
+
uses: meltwater/sec-global-gh-actions/.github/workflows/codeql-horusec-analysis.yml@main
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getInsights = getInsights;
|
|
7
|
+
exports.getMediaFromId = getMediaFromId;
|
|
7
8
|
exports.getProfile = getProfile;
|
|
8
9
|
exports.manageReply = manageReply;
|
|
9
10
|
exports.quote = quote;
|
|
@@ -234,6 +235,26 @@ async function manageReply(token, externalId) {
|
|
|
234
235
|
return response.body;
|
|
235
236
|
}
|
|
236
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Retrieves media information from Threads.
|
|
240
|
+
* @param {string} token - The access token for authentication.
|
|
241
|
+
* @param {string} externalId - The external ID of the media.
|
|
242
|
+
* @param {string} fields - The fields to retrieve from the media.
|
|
243
|
+
* @param {Object} logger - Logger instance for logging.
|
|
244
|
+
* @returns {Promise<Object>} The API response containing the media information.
|
|
245
|
+
*/
|
|
246
|
+
async function getMediaFromId(token, externalId, fields, logger) {
|
|
247
|
+
const mediaId = (0, _externalIdHelpers.removePrefix)(externalId);
|
|
248
|
+
let response = await sendRequest(`${THREADS_URL}/${mediaId}`, {
|
|
249
|
+
access_token: token,
|
|
250
|
+
fields
|
|
251
|
+
}, logger);
|
|
252
|
+
(0, _loggerHelpers.loggerInfo)(logger, `Native Threads API getMediaFromId Response`, {
|
|
253
|
+
responseBody: JSON.stringify(response.body)
|
|
254
|
+
});
|
|
255
|
+
return response.body;
|
|
256
|
+
}
|
|
257
|
+
|
|
237
258
|
/**
|
|
238
259
|
* Constructs the query parameters for replying to a post.
|
|
239
260
|
* @param {string} accessToken - The access token for authentication.
|
|
@@ -504,6 +504,14 @@ async function doRequest(_ref4) {
|
|
|
504
504
|
}
|
|
505
505
|
});
|
|
506
506
|
} catch (e) {
|
|
507
|
+
if (e.response.status == 503) {
|
|
508
|
+
loggerWarn(logger, `Twitter API 503 error - Service Unavailable`, {
|
|
509
|
+
url,
|
|
510
|
+
convertPayloadToUri,
|
|
511
|
+
payload: JSON.stringify(payload)
|
|
512
|
+
});
|
|
513
|
+
return reject(e);
|
|
514
|
+
}
|
|
507
515
|
(0, _loggerHelpers.loggerError)(logger, `Error in twitter doRequest`, e, {
|
|
508
516
|
url,
|
|
509
517
|
convertPayloadToUri,
|
|
@@ -7,6 +7,7 @@ exports.MeltwaterAttributes = void 0;
|
|
|
7
7
|
exports.loggerDebug = loggerDebug;
|
|
8
8
|
exports.loggerError = loggerError;
|
|
9
9
|
exports.loggerInfo = loggerInfo;
|
|
10
|
+
exports.loggerWarn = loggerWarn;
|
|
10
11
|
const MeltwaterAttributes = exports.MeltwaterAttributes = {
|
|
11
12
|
COMPANYID: 'meltwater.company.id',
|
|
12
13
|
// Unique identifier of a company as it applies to meltwater search
|
|
@@ -77,4 +78,12 @@ function loggerError(logger, message) {
|
|
|
77
78
|
} else {
|
|
78
79
|
console.log(message, meta);
|
|
79
80
|
}
|
|
81
|
+
}
|
|
82
|
+
function loggerWarn(logger, message) {
|
|
83
|
+
let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
84
|
+
if (logger) {
|
|
85
|
+
logger.warn(message, meta);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(message, meta);
|
|
88
|
+
}
|
|
80
89
|
}
|
|
@@ -222,6 +222,26 @@ export async function manageReply(token, externalId) {
|
|
|
222
222
|
return response.body;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves media information from Threads.
|
|
227
|
+
* @param {string} token - The access token for authentication.
|
|
228
|
+
* @param {string} externalId - The external ID of the media.
|
|
229
|
+
* @param {string} fields - The fields to retrieve from the media.
|
|
230
|
+
* @param {Object} logger - Logger instance for logging.
|
|
231
|
+
* @returns {Promise<Object>} The API response containing the media information.
|
|
232
|
+
*/
|
|
233
|
+
export async function getMediaFromId(token, externalId, fields, logger) {
|
|
234
|
+
const mediaId = removePrefix(externalId);
|
|
235
|
+
let response = await sendRequest(`${THREADS_URL}/${mediaId}`, {
|
|
236
|
+
access_token: token,
|
|
237
|
+
fields
|
|
238
|
+
}, logger);
|
|
239
|
+
loggerInfo(logger, `Native Threads API getMediaFromId Response`, {
|
|
240
|
+
responseBody: JSON.stringify(response.body)
|
|
241
|
+
});
|
|
242
|
+
return response.body;
|
|
243
|
+
}
|
|
244
|
+
|
|
225
245
|
/**
|
|
226
246
|
* Constructs the query parameters for replying to a post.
|
|
227
247
|
* @param {string} accessToken - The access token for authentication.
|
|
@@ -481,6 +481,14 @@ async function doRequest(_ref4) {
|
|
|
481
481
|
}
|
|
482
482
|
});
|
|
483
483
|
} catch (e) {
|
|
484
|
+
if (e.response.status == 503) {
|
|
485
|
+
loggerWarn(logger, `Twitter API 503 error - Service Unavailable`, {
|
|
486
|
+
url,
|
|
487
|
+
convertPayloadToUri,
|
|
488
|
+
payload: JSON.stringify(payload)
|
|
489
|
+
});
|
|
490
|
+
return reject(e);
|
|
491
|
+
}
|
|
484
492
|
loggerError(logger, `Error in twitter doRequest`, e, {
|
|
485
493
|
url,
|
|
486
494
|
convertPayloadToUri,
|
|
@@ -69,4 +69,12 @@ export function loggerError(logger, message) {
|
|
|
69
69
|
console.log(message, meta);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
export function loggerWarn(logger, message) {
|
|
73
|
+
let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
74
|
+
if (logger) {
|
|
75
|
+
logger.warn(message, meta);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(message, meta);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
72
80
|
export { MeltwaterAttributes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Repository to contain all conversations api services shared across our services",
|
|
5
5
|
"main": "dist/cjs/data-access/index.js",
|
|
6
6
|
"module": "dist/esm/data-access/index.js",
|
|
@@ -294,6 +294,28 @@ export async function manageReply(token, externalId, hide = false, logger) {
|
|
|
294
294
|
return response.body;
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Retrieves media information from Threads.
|
|
299
|
+
* @param {string} token - The access token for authentication.
|
|
300
|
+
* @param {string} externalId - The external ID of the media.
|
|
301
|
+
* @param {string} fields - The fields to retrieve from the media.
|
|
302
|
+
* @param {Object} logger - Logger instance for logging.
|
|
303
|
+
* @returns {Promise<Object>} The API response containing the media information.
|
|
304
|
+
*/
|
|
305
|
+
export async function getMediaFromId(token, externalId, fields, logger) {
|
|
306
|
+
const mediaId = removePrefix(externalId);
|
|
307
|
+
let response = await sendRequest(
|
|
308
|
+
`${THREADS_URL}/${mediaId}`,
|
|
309
|
+
{ access_token: token, fields },
|
|
310
|
+
logger
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
loggerInfo(logger, `Native Threads API getMediaFromId Response`, {
|
|
314
|
+
responseBody: JSON.stringify(response.body),
|
|
315
|
+
});
|
|
316
|
+
return response.body;
|
|
317
|
+
}
|
|
318
|
+
|
|
297
319
|
/**
|
|
298
320
|
* Constructs the query parameters for replying to a post.
|
|
299
321
|
* @param {string} accessToken - The access token for authentication.
|
|
@@ -578,6 +578,14 @@ async function doRequest({
|
|
|
578
578
|
resp: { ...result },
|
|
579
579
|
});
|
|
580
580
|
} catch (e) {
|
|
581
|
+
if(e.response.status == 503){
|
|
582
|
+
loggerWarn(logger,`Twitter API 503 error - Service Unavailable`,{
|
|
583
|
+
url,
|
|
584
|
+
convertPayloadToUri,
|
|
585
|
+
payload: JSON.stringify(payload),
|
|
586
|
+
});
|
|
587
|
+
return reject(e);
|
|
588
|
+
}
|
|
581
589
|
loggerError(logger,`Error in twitter doRequest`, e, {
|
|
582
590
|
url,
|
|
583
591
|
convertPayloadToUri,
|
|
@@ -48,4 +48,12 @@ export function loggerError(logger, message, meta = {}) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export function loggerWarn(logger, message, meta = {}) {
|
|
52
|
+
if(logger){
|
|
53
|
+
logger.warn(message, meta);
|
|
54
|
+
}else{
|
|
55
|
+
console.log(message,meta);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
export { MeltwaterAttributes };
|